/ Published in: JavaScript
JS Function that style sibling elements of a given tag. Arguments: tag of the element We want siblings to style and name of the class we want to add. It needs the class to be styled (using CSS). It uses getNextElement function and addClass functions.
From book Dom Scripting by Jeremy Keith.
From book Dom Scripting by Jeremy Keith.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function styleElementSiblings(tag,theclass) { if (!document.getElementsByTagName) return false; var elems = document.getElementsByTagName(tag); var elem; for (var i=0; i<elems.length; i++) { elem = getNextElement(elems[i].nextSibling); addClass(elem,theclass); } }