<p class="swim">Swim</p>
It clearly contains the text "swim", but this is held in a text node, which is the first child of the swim node:
swimTextNode = swim.firstChild;
<< #text "Swim
<< #text "Swim
Now that we have a reference to the text node, we can find the text contained inside it using the nodeValue method:
swimTextNode.nodeValue;
<< "Swim"
<< "Swim"
A quicker way of doing this is to use the textContent property. This will return the text content of an element as a string:
swim.textContent
<< "Swim"
<< "Swim"
Note that Internet Explorer version 8 does not support the textContent property, but has the innerText property, which works in a similar way.
0 Response to "Finding the Value of a Node"
Post a Comment