jskidd3
jskidd3

Reputation: 4783

Getting child node value of child's child

Below I have code to find the node value of 'TheNode'. I need to adapt that code so that it gets the node value of <Child>. How can this be done?

XML:

<BigParent>
    <Parent>
        <Child>Please get my value!!!</Child>
    </Parent>
</BigParent>

JavaScript (that needs changing (so I can find <Child> value)):

$(data).find('TheNode').each(function() {
  var childNode = this.childNodes[0];
  var childNodeValue = childNode.nodeValue;
});

Thanks

Upvotes: 0

Views: 2257

Answers (2)

Frank
Frank

Reputation: 775

jQuery("<BigParent><Parent><Child>Please get my value!!!</Child></Parent></BigParent>").find("Child").text()

returns the value

Upvotes: 0

Hamza Kubba
Hamza Kubba

Reputation: 2269

$(data).find('TheNode').children().first().text();

Upvotes: 2

Related Questions