Reputation: 7969
i am getting data from XML into html using jquery, i build a function which is working perfectly which is given below
function parseXml(xml){
xmlcontent = xml;
$('#file').html('$'+ GetDeals('delhi','india'));
$('#file1').html('$'+ GetDeals('mumbai','india'));
$('#file2').html('$'+ GetDeals('kolkata','india'));
}
function GetDeals(state, country){
var lowestPrice=0;
$(xmlcontent).find("ndata[nstate='"+state+"'][ncountry='"+ country +"']").each(function(){
lowestPrice = parseInt($(this).attr('price')) ;
});
return lowestPrice;
}
now i want pick pick one more field call cityrating from xml for example first parameter contains cityrating= 1, and second cityrating=2, and last one is 3 and i wana get it in new div, i struggle with it almost 3 hour but it is not working my change function given below. when i am running this function cityrating replace by last cityrating for example all parameter cityrating replaced by 3
function parseXml(xml){
xmlcontent = xml;
$('#file').html('$'+ GetDeals('delhi','india'));
$('#file1').html('$'+ GetDeals('mumbai','india'));
$('#file2').html('$'+ GetDeals('kolkata','india'));
}
function GetDeals(state, country){
var lowestPrice=0;
var cityRating=[];
$(xmlcontent).find("ndata[nstate='"+state+"'][ncountry='"+ country +"']").each(function(){
lowestPrice = parseInt($(this).attr('price'));
cityRating.push(parseInt($(this).attr('CityRating')));
$('.city').html(cityRating[0])
});
return lowestPrice;
}
//my html
<div id="file"></div>
<div class="city"></div>
<div id="file1"></div>
<div class="city"></div>
<div id="file2"></div>
<div class="city"></div>
Upvotes: 0
Views: 335
Reputation: 723
I see that you are trying to find an element with class city
which does not exist.
It should be $('#city').html(cityRating[0])
instead $('.city').html(cityRating[0])
Upvotes: 2