Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding the Div with JavaScript 2

Status
Not open for further replies.

bean1234

Technical User
Nov 14, 2006
45
US
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.

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);
   
  }
 
clFlava,

The style definition is in a CSS file as follows

Code:
div.container{

     display: block;
}

and I am setting the class of the div that I need to hide/show as followis

<div class = "container">
</div>
 
and that is precisely the problem.

set up another style class:

Code:
div.hidden {
    display: none;
}

and rather than setting the style, set the className.

apparently you did not want to read my thread about "gettin' jiggy wit' it" above...



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Awesome , ClFlava,

Yes you were right , but how did you know that changing teh style wont work and changing the classname will work, also I really thank you for anwering all my questions...You have been of tremendous help dude...
 
how do i know? haha...

i (obviously) just spend entirely too much time on this forum. basically, you start seeing patterns. why doesn't this work? this is how i have it set up... you start remembering the answers you've given other people.

no problem, glad to help.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
slightly off topic, but did you buy your car yet?
 
:)!!!

no -- the dealer is actually on vacation today and tomorrow (who does that?? especially when they know i want to buy?) so i'm meeting with him thursday to lay down the law. if he doesn't bite i'll order from another dealership, where i'm getting the car at-cost.

after i order it, it'll take about six weeks to arrive.

thanks for asking!



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top