I have an xml file xyz.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<legends>
<legend>
<number>1</number>
<contentString>abcd</contentString>
</legend>
<legend>
<number>2</number>
<contentString>efg</contentString>
</legend>
<legend>
<number>3</number>
<contentString>hij</contentString>
</legend>
</legends>
I am trying to read this with jQuery:
$(document).ready(function() {
$.get("xyz.xml",{},function(xml){
var randomnumber=Math.floor(Math.random()*3);
$('legend',xml).each(function() {
if(randomnumber == $(this).find("number").text())
{
var c = "contentString";
var legendStr = $(this).find(c).text();
alert(legendStr);
}
});
});
});
The jQuery code is not entering inside the function $('legend',xml).each(function().
Why this is happening.