XML jquery shortcuts
- by Llamabomber
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...