Return to Snippet

Revision: 50424
at August 20, 2011 21:11 by alberomo


Initial Code
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);  
  }
}

Initial URL


Initial Description
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.

Initial Title
styleElementSiblings Function

Initial Tags
javascript

Initial Language
JavaScript