Reputation: 3500
i am fetching xml by using ajax/jquery, suppose my xml is
<root>
<parent name="p1">
<child name="c1" value="1"/>
<child name="c2" value="2"/>
</parent>
<parent name="p2">
<child name="c3" value="3"/>
<child name="c4" value="4"/>
</parent>
</root>
now i want to read only values of child of "p2" not "p1" i.e. (3,4),
normal jquery code i.e.
$(result).find("child").each(function(){
value1=$(this).attr("value");
alert(value1);
});
is not working here... it will also return "1" & "2" which i dont want.
can anybody pls tell me, how can i achieve this ?
Upvotes: 0
Views: 60
Reputation: 4351
You can modify your child
selector to be more specific
$(result).find("parent[name='p2'] child").each(function(){
value1=$(this).attr("value");
alert(value1);
});
Upvotes: 2