Erik Knutsson
Erik Knutsson

Reputation: 3

XML get certain node with specific attribute

Hi Iam a beginner in XML and javascript. But I want to select a node that contains "insurance will". I want to do this because there are nodes with same node name that can contain different text. The XML file can look like this.

<Description>Hi hello</Description>
<Description>insurance will</Description>
<Description>come here</Description>
<Description>lalaland</Description>

Upvotes: 0

Views: 1051

Answers (1)

Florian Margaine
Florian Margaine

Reputation: 60717

var descs = document.getElementsByTagName( 'Description' );
for ( var i = 0, len = descs.length; i < len; i++ ) {
    if ( descs[ i ].textContent === 'insurance will' ) {
        // This node is the right one!
    }
}

Upvotes: 1

Related Questions