topical media & game development
#javascript-code-09-getbytagname.js / js
// Find all <div> Elements in the current HTML document
// and set their class to ‘hilite’
var d = document.getElementsByTagName(“div”);
for ( var i = 0; i < d.length; i++ ) {
d[i].className = ‘hilite’;
}
// Go through all descendant elements of the element with
// an ID of body. Then find all elements that have one class
// equal to ‘hilite’. Then hide all those elements that match.
var all = document.getElementById(“body”).getElementsByTagName(“*”);
for ( var i = 0; i < all.length; i++ ) {
if ( all[i].className == ‘hilite’ )
all[i].style.display = ‘none’;
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.