How to check an element if it is text node or not?
Plz help.
Kind regards,
Dmjpro.
Its very simple:
<script language="JavaScript"
type="text/javascript">
window.onload = function() {
var s = "";
with (document.getElementById("para")) {
for (var i=0; i<childNodes.length; i++) {
with (childNodes[i]) {
s += nodeName + ": " + nodeValue +
" (" + nodeType + ")\n";
}
}
}
window.alert(s);
}
</script>
<p id="para"><em>JavaScript</em> Phrasebook</p>
nodeType stores the info of type of node.
these are typical nodeTypes
Node Type
Description
1 Tag
2 Attribute
3 Text (includes whitespace)
8 HTML comment
9 Document
10 DTD
11 Fragment