Other methods of DOM


This method is used to find out if a particular parent has child in its or not. It basically returns true if it has some sub-components in it, else false.

           <ol id='ol1'>
                <li id='li1'>
                       <span id='span1'>
                             This is Text 1
                  <li id='li2'>
                        <span id='span2'>
                              This is Text 2
                 <li id='li3'>
                        <span id='span3'>
                              This is Text 3
Talking in the sense of above example ,
	document.getElementById("span3").hasChildNodes() will return true
	Using nodeName returns the name of the node. Ex :-
	document.getElementById("span3").nodeName returns SPAN

Besides, we also have nodeType defined on the basis of what type of node it is actually.

nodeType returns :- 
1 if it is an element
2 if it is an attribute
3 if it is text

nodeValue returns value of the node. We can use this to retrieve or change this value. If the node is a text node (nodeType of 3), it returns the text; if it is an attribute (nodeType of 2), it returns the value of that attribute; if it's an element (nodeType of 1), it returns null. Text will return it's value: -

returns "This is Text 3," while an element returns null:
returns null.

Lets proceed to attributes now :-

Member Login

Member Login

Not a Member? Sign Up!

Login to comment

Be the first to comment on this topic


<<< Wanna review

Continue >>>