- #1
- 9,623
- 9
I have some divs on a web page, with the class name "hans" which I would like to hide with JavaScript when the page loads. The reason I have it set up this way is so that the user can reveal the div's by clicking a link, but if JavaScript is disabled, the div's will be displayed by default. I've written a loop to loop through the document and hide all the divs, but it doesn't seem to be working. All the divs have unique ID's. The toggle() function used below is a function that just toggle's a named div between display:none; and display:block;
Any help would be much appreciated.
Code:
function hideans() {
var boxes = document.getElementsByTagName("div");
for(var i=0;i<boxes.length;i++) {
var boxClass = boxes[i].className;
if(boxClass.match("hans")) {
toggle(boxes[i]);
}
}
}
Any help would be much appreciated.