We recently needed to create an HTML page and dynamically hide/show an entire class of <div> tags that were interspersed throughout the page. Using the getElementsByTagName javascript method, we were able to iterate over all of the <div> elements in the document. Then check the CSS class by accessing the className DOM element:
oDivs = document.getElementsByTagName ( “div” );
for ( d = 0; d < oDivs.length; d++ ) {
for ( d = 0; d < oDivs.length; d++ ) {
// cl_name = oDivs[ d ].getAttribute ( “class” ); // does NOT work in IE
cl_name = oDivs[ d ].className;
if ( cl_name == “bio” ) {
cl_name = oDivs[ d ].className;
if ( cl_name == “bio” ) {
oDivs[ d ].style.display = “none”;
}
}
Note that the getAttribute method does not work in IE since class is a reserved word for IE. Took us a little while to figure that one out.