djp1988 Posted August 3, 2008 Share Posted August 3, 2008 Hi, I have the following script that changes the display of a set of div's but I have other divs inside of these divs and because I set the display of all of the div's to none and then only the div triggered to be display:block, the child div's are also hidden, how can I make it so all the div's inside the triggered div also become visible? function showdiv(div) { divs = document.getElementById('info').getElementsByTagName('div'); if(document.getElementById(div).style.display != "block"){ for (i = 0; i < divs.length; i++) { divs[i].style.display = "none"; divs[i].style.opacity = "0"; divs[i].style.filter = "alpha(opacity=0)"; } document.getElementById(div).style.display = "block"; shiftOpacity(div, 500); } } I thought of something like: function showdiv(div) { divs = document.getElementById('info').getElementsByTagName('div'); if(document.getElementById(div).style.display != "block"){ for (i = 0; i < divs.length; i++) { divs[i].style.display = "none"; divs[i].style.opacity = "0"; divs[i].style.filter = "alpha(opacity=0)"; } document.getElementById(div).style.display = "block"; document.getElementById(div).childNodes.style.display = "block"; shiftOpacity(div, 500); } } Link to comment Share on other sites More sharing options...
Ingolme Posted August 3, 2008 Share Posted August 3, 2008 Why not display all the divs except for the main one as a block to begin with? Link to comment Share on other sites More sharing options...
jeffman Posted August 3, 2008 Share Posted August 3, 2008 What Ingolme said.FWIW, childNodes is a list, not an element, so it doesn't have a style property you can access. You can, however, treat it like an array and index your way through it. Link to comment Share on other sites More sharing options...
djp1988 Posted August 3, 2008 Author Share Posted August 3, 2008 at the start there is one of the div's as display:block' but when you click on a link, the div changes to display:none and the corresponding div is made visible display:blockhow can I treat is as an array ? Link to comment Share on other sites More sharing options...
jeffman Posted August 3, 2008 Share Posted August 3, 2008 how can I treat is as an array ? nodz = document.getElementById("my_ID").childNodes;for (var i = 0; nodz[i]; i++) { if (nodz[i].nodeName.toUpperCase() == "IMG") { // xhtml nodeNames are lower case //DO SOMETHING }} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.