开发者

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 within xmlDocument
  • .eq() to reduce the set of sitelists to only the 4th one (index of 3)
  • .children() to find all the direct children of the 4th sitelist
  • :first selector to only pick the first child.
  • .text() to retrieve the text in that node
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜