tags:

views:

61

answers:

2

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 performing 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

+2  A: 
$('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.

jAndy
Woudln't it be `eq(3)`, since it's `coursename[3]` in the original?
Peter Ajtai
A: 
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
Peter Ajtai