Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 15th, 2012  |  syntax: JavaScript  |  size: 0.70 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Returns a list of elements of class class_name                                                                                                                                              
  2. function getElementsByClassName(els, class_name) {
  3.     return ch_filter(els, function (el) { return el.getAttribute("class") == class_name ? true : false });
  4. }
  5.  
  6. // A filter function even IE6 will understand                                                                                                                                                  
  7. function ch_filter(a, fn) {
  8.     if(a.filter) return a.filter(fn);
  9.     var r = [];
  10.     for(i = 0; i < a.length; i++)
  11.         if(fn(a[i])) r.push(a[i]);
  12.     return r;
  13. }