javascript - how to read attribute in line of file XML use jquery -
i trying read attribute of line in file xml using jquery.
this xml:
<?xml version="1.1" encoding="utf-8"?> <biology> <item> <image type="test">cafroost.gif</image> <sound>cafroost.wav</sound> <name>cà rốt</name> </item> <item> <image type="write">cafroost.gif</image> <sound>cafroost.wav</sound> <name>cà rốt</name> </item> </biology>
this code read file xml:
$("#ajaxbutton").click(function(){ $.get('js/data.xml', function(xml){ var biology = $.xml2json(xml); len = biology.item.length; alert(biology.item[0].image); }) });
i try read attribute "type" like:
alert(biology.item[0].image.attr("type"));
but it's not work. know how read attribute??
i newbie. please me.
thanks reading.!!!
you need
var type = biology.find('item > image').eq(0).attr('type')
Comments
Post a Comment