Reputation: 1570
I have XML:
<street></street>
or
<street>2813 Bla ave</street>
Javascript:
if ((xmldoc.getElementsByTagName('street')[i].firstChild.nodeValue != null)) {
alert(1);
}
alert(2);
But the script doesn't work - Cannot read property 'nodeValue' of null
Upvotes: 2
Views: 21482
Reputation: 14319
Use xmldoc.getElementsByTagName('street')[i].innerHTML because the text you want is between the tags. I believe this IS supported for XML. Of course, you could always use the nodeValue property as well.
Upvotes: 0
Reputation: 6529
The street node does not have any children. You need to remove .firstChild
Upvotes: 0
Reputation: 2978
Your selector is failing,
xmldoc.getElementsByTagName('street')[i].firstChild
appears to return null. Have you tried logging and checking to make sure that the selector you want actually exists?
Upvotes: 0
Reputation: 324790
nodeValue
will never be null
because without a value the node wouldn't exist.
Remove .nodeValue
from your code.
Upvotes: 3