I have the following xml file which I'm trying to read with JQuery
<albums startAlbumNo="1">
<album id="1">
<author>author1</author>
<image>images/2010-1-web-ready.jpg</image>
<caption>caption1</caption>
<tracks>
<item id="31">
<title>title1</title>
<artist>artist1</artist>
<song>content/stories/ChristmasStory.mp3</song>
</item>
<item id="32">
<title>title2</title>
<artist>artist2</artist>
<song>content/stories/ChristmasStory2.mp3</song>
</item>
</tracks>
</album>
//similiar albums below
<album>....</album>
<album>....</album>
<album>....</album>
</albums>
And I have the following JQuery to read it
$(document).ready(function(){ //run when page loads
var buttonNames = new Array();
var foo;
function parse(document){ //extract song locations from mp3gallery.xml based upon album
buttonNames[0] = $(document).find('album[id="1"]').find("tracks").find("title").eq(0).text(); //this works
$(document).find("album").each(function(){ //this does not
alert('1'); //never runs
foo = $(this).find('image').text();
}
alert(foo); //never runs
changeButtonNames();
}
$.ajax({
url: 'mp3gallery/xml/mp3gallery.xml', // name of file you want to parse
dataType: "xml",
success: parse, //on success calls the "parse" function
error: function(){alert("Error: Something went wrong");}
});
function changeButtonNames(){ //has to be run last
document.getElementById('btn1').innerHTML = buttonNames[0];
}
});
the
$(document).find('album[id="1"]').find("tracks").find("title").eq(0).text();
runs fine, however my .each loop does nothing.
I have been looking at numerous examples for a while with no success. I am probably missing something obvious. Thanks for your help!
document, maybe try changing that to something likexml