/* * Copyright 2004-2006 Toni Corvera * * License: http://www.gnu.org/copyleft/lgpl.html LGPL * * Extra DOM-like methods (Note that at the time of writing they can't be * bound to the Document prototype, so they are global functions) * NOTE IT REQUIRES THE Array.merge METHOD FOUND IN MY SITE! * * getFirstChildByTagName(HTMLElement parent, String tagName) * First child of parent with tag tagName, NOT-RECUSIVE * getFirstSiblingByTagName(HTMLElement node, String tagName) * See above * getChildrenByClassName(Node parent, String className) * Obtains an array with the children of parent that have * the class className (supports multi-class elements), NOT-RECURSIVE * getChildrenByTagName(Node parent, String tagName) * Obtains an array with the children of parent that have * the tag tagName, NOT-RECURSIVE * * hasClass(HTMLElement element, String className) * Checks if element has class className, supports multi-class elements * removeClass(HTMLElement element, String className) * Remove class className from element's classes if present, supports * multi-class elements */ // boolean hasClass(HTMLElement e, String className) function hasClass(e, c) { if(!document.getElementById)return false; if (!e.className) return false; return null!=e.className.match(new RegExp('^(\w*|.* )'+c+'(\w*| .*)$')); } // void removeClass(HTMLElement e, String className) function removeClass(e, c) { if(!hasClass(e, c))return; e.className = e.className.replace(new RegExp(c,'g'),''); } // HTMLElement getFirstChildByTagName(HTMLElement parent, String tagName) function getFirstChildByTagName(e,tag){ if (!document.getElementById) return null; var f=null; for (var i=0;i