Posted By

alberomo on 08/20/11


Tagged

javascript manual


Versions (?)

styleElementSiblings Function


 / 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.

  1. function styleElementSiblings(tag,theclass) {
  2. if (!document.getElementsByTagName) return false;
  3. var elems = document.getElementsByTagName(tag);
  4. var elem;
  5. for (var i=0; i<elems.length; i++) {
  6. elem = getNextElement(elems[i].nextSibling);
  7. addClass(elem,theclass);
  8. }
  9. }

Report this snippet  

You need to login to post a comment.