scripts/domutils.js
changeset 11 0faea3a6c881
parent 2 860ba7141641
child 58 05a69bab5f10
--- a/scripts/domutils.js	Mon Mar 24 02:53:42 2008 -0400
+++ b/scripts/domutils.js	Wed Mar 26 09:57:42 2008 -0400
@@ -95,3 +95,29 @@
   return text;
 }
 
+// Tell which elements have the specified CSS class
+// Parameters:
+//   * object - HTMLElement
+//   * string - class name
+//   * string - tag name, if omitted will test all elements (slow)
+function getElementsByClassName(oRoot, className, tagName)
+{
+  tagName = ( tagName ) ? tagName : '*';
+  var arrEls = document.getElementsByTagName(tagName);
+  var arrResult = [];
+  for ( var i = 0; i < arrEls.length; i++ )
+  {
+    if ( $(arrEls[i]).hasClass(className) )
+    {
+      arrResult.push(arrEls[i]);
+    }
+  }
+  return arrResult;
+}
+
+// shortcut :)
+document.getElementsByClassName = function(a, b)
+{
+  return getElementsByClassName(document, a, b);
+}
+