scripts/domutils.js
changeset 11 0faea3a6c881
parent 2 860ba7141641
child 58 05a69bab5f10
equal deleted inserted replaced
10:d3059e20b0fa 11:0faea3a6c881
    93   text = text.replace(/^([\s]+)/, '');
    93   text = text.replace(/^([\s]+)/, '');
    94   text = text.replace(/([\s]+)$/, '');
    94   text = text.replace(/([\s]+)$/, '');
    95   return text;
    95   return text;
    96 }
    96 }
    97 
    97 
       
    98 // Tell which elements have the specified CSS class
       
    99 // Parameters:
       
   100 //   * object - HTMLElement
       
   101 //   * string - class name
       
   102 //   * string - tag name, if omitted will test all elements (slow)
       
   103 function getElementsByClassName(oRoot, className, tagName)
       
   104 {
       
   105   tagName = ( tagName ) ? tagName : '*';
       
   106   var arrEls = document.getElementsByTagName(tagName);
       
   107   var arrResult = [];
       
   108   for ( var i = 0; i < arrEls.length; i++ )
       
   109   {
       
   110     if ( $(arrEls[i]).hasClass(className) )
       
   111     {
       
   112       arrResult.push(arrEls[i]);
       
   113     }
       
   114   }
       
   115   return arrResult;
       
   116 }
       
   117 
       
   118 // shortcut :)
       
   119 document.getElementsByClassName = function(a, b)
       
   120 {
       
   121   return getElementsByClassName(document, a, b);
       
   122 }
       
   123