jquery - select XML attribute and pop into a table -
i tring make button user can select filter stores want , see result in table. example, select xml rows state attribute equals a. nothing returned, please advise if syntax has problems. thanks.
<markers> <marker name="store a" address="1 abc street" state="a" phone="1234567" /> <marker name="store b" address="2 abc street" state="b" phone="1234567" /> <marker name="store c" address="3 abc street" state="a" phone="1234567" />
<input type='button' name='select1' value="a" onclick="changefilter(this.value);"> function changefilter(ctry){ $country=ctry; $(".datarow").remove(); loadtable($xmldata); } function loadtable(data){ $xmldata=data; $(data).find("marker[state=" + ctry + "]").each(function(){ var $this=$(this); var $name=$this.find('marker[name]').text(); var $tel=$this.find('marker[phone]').text(); var $country=$this.find('marker[address]').text(); $("#datatable").append("<tr class='datarow'><td>"+$name+"</td><td>"+$tel+"</td><td>"+$country+"</td></tr>"); }); }
you need use .attr()
method inorder attribute value.
$("div").find("marker[state=" + ctry + "]").each(function(){ var $this=$(this); var $name=$this.attr("name"); var $tel=$this.attr("phone"); var $country=$this.attr("address"); });
Comments
Post a Comment