0

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;
    }
}
1

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

That's it. I would of never though of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.