get tag names and first child data with Jquery
Hi I am trying to retrieve data from the child data of a tag from my ajax script. this works with javascript
coursename = xmlDocument.getElementsByTagName("sitelist");
name = coursename[3].firstChild.data
Can somebody help me with pe开发者_如何学运维rforming this using jQuery please? I thought this would work but it doesn't.
name = $("coursename", xml).text()
Any help or pointers would be great, thanks.
$('sitelist:eq(2)')
is the jQuery selector for that. You might want to use jQuerys .data()
method as well to store something to that node.
name = $("sitelist", xmlDocument).eq(3).children(":first").text();
The above uses:
- jQuery context to choose all
sitelist
tags withinxmlDocument
.eq()
to reduce the set ofsitelist
s to only the 4th one (index of 3).children()
to find all the direct children of the 4thsitelist
:first selector
to only pick the first child..text()
to retrieve the text in that node
精彩评论