Hello All,
I have a scenario where I need to hide all the elements with in a Div after a link is clicked.The elements with in DIv are aslo divs,but when I get the childNodes array by using div.childNodes attribute I always get the length of array as 1 and it doesnt return all the child elements.Please look at the following HTML and the associated JavaScript to understand the problem.
As you can see the a toplevel div encloses other divs, it has a link that calls the following JavaScript function, in the function the length of the childNodes collection is always 1 and unable to iterate over the elemnts in the childNodes collection.
I have a scenario where I need to hide all the elements with in a Div after a link is clicked.The elements with in DIv are aslo divs,but when I get the childNodes array by using div.childNodes attribute I always get the length of array as 1 and it doesnt return all the child elements.Please look at the following HTML and the associated JavaScript to understand the problem.
Code:
<div class="d0"> <a href="#" onClick="return toggle
(this);">External</a>
<div class="d1" >
<a>Name</a>
</div>
<div class="d0" >
<a>Publications </a>
</div>
<div class="d1" >
<a >Cybrary Direct</a>
</div>
<a>CEO Express</a>
</div>
</div>
As you can see the a toplevel div encloses other divs, it has a link that calls the following JavaScript function, in the function the length of the childNodes collection is always 1 and unable to iterate over the elemnts in the childNodes collection.
Code:
function toggle(parentDiv){
alert('The length of the childNodes array is '+parentDiv.childNodes.length);
}