Amauri
Amauri

Reputation: 550

for-loop if statement not entering

The point is to filter through the nodes of an array and find the paragraph. The if statement is conditional tester is always false, hence never going in. But when I tested the node names using alerts, the 4th one is actually p.

//b is an array filled with 5 DOM Nodes one of which is a <p/>
for(var i=0;i<5;i++)
{   alert(b[i].nodeName);   //b[3].nodeName alerts p
    if(b[i].nodeName=="p")
    {
        //do something
        break;
    }
    else
    {
        continue;
    }
}

Upvotes: 0

Views: 267

Answers (1)

Mitya
Mitya

Reputation: 34556

nodeName returns the tag name in uppercase (as does .tagName()); you're comparing it against lowercase.

Upvotes: 4

Related Questions