Revision: 2421
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 13, 2007 05:40 by 1man
Initial Code
window.onload = function() { var headers = document.getElementsByTagName("h1");//grab all h1's for(i=0; i<headers.length; i++) {//loop through the h1's var elem = getNextElement(headers[i].nextSibling);//look for the next sibling of the h1 //apply these styles to the selected elements elem.style.color = "red"; elem.style.backgroundColor = "black"; } } //getNextElement function function getNextElement(node) { if(node.nodeType == 1){ return node; } if(node.nextSibling) { return getNextElement(node.nextSibling) } return null; }
Initial URL
Initial Description
Usage of the getNextElement function. Very basic usage to pick out the h1 tags, then change the properties of the next element(not node).
Initial Title
Usage of getNextElement Function
Initial Tags
js, DOM
Initial Language
JavaScript