XML jquery shortcuts
Posted
by Llamabomber
on Stack Overflow
See other posts from Stack Overflow
or by Llamabomber
Published on 2010-04-26T17:01:22Z
Indexed on
2010/04/26
17:03 UTC
Read the original article
Hit count: 227
I am writing a bit of code that appends my site nav with and extra ul that gives a description about where that link takes you. I need to use our CMS's built in Nav structure so appending via jQuery was the best solution, and XML makes the data easier to manage. My question is this: is there a more efficient way to write out the js? What I have so far is this:
$(document).ready(function()
{
$.ajax({
type: "GET",
url: "/js/sitenav.xml",
dataType: "xml",
success: function parseXml(xml) {
// WORK
$(xml).find("CaseStudies").each(function()
{
$("li#case_studies").append('<ul><li>' + $(this).find("NavImage").text() + $(this).find("NavHeader").text() + $(this).find("NavDescription").text() + $(this).find("NavLink").text() + "</li></ul>");
});
};
});
});
and the xml structure resembles this:
<SiteNav>
<Work>
<CaseStudies>
<NavImage></NavImage>
<NavHeader></NavHeader>
<NavDescription></NavDescription>
<NavLink></NavLink>
</CaseStudies>
</Work>
</SiteNav>
I'm happy with my xml structure, but is there a more compact/efficient method of writing out the code for the jqeury? Every li in the nav has a unique id as well in case that helps...
© Stack Overflow or respective owner