Posted By

otaqui on 02/08/08


Tagged

javascript textmate


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

SpinZ
mifly


GetElementsByClassName


 / Published in: JavaScript
 

  1. function getElementsByClassName(className, tag, elm){
  2. var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
  3. var tag = tag || "*";
  4. var elm = elm || document;
  5. var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
  6. var returnElements = [];
  7. var current;
  8. var length = elements.length;
  9. for(var i=0; i<length; i++){
  10. current = elements[i];
  11. if(testClass.test(current.className)){
  12. returnElements.push(current);
  13. }
  14. }
  15. return returnElements;
  16. }

Report this snippet  

You need to login to post a comment.