Posted By


fulvius on 12/04/10

Tagged


Statistics


Viewed 59 times
Favorited by 1 user(s)

getElementsByClassName


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function getElementsByClassName(classname, node) {
  2. if(!node) node = document.getElementsByTagName("body")[0];
  3. var a = [];
  4. var re = new RegExp('\\b' + classname + '\\b');
  5. var els = node.getElementsByTagName("*");
  6. for(var i=0,j=els.length; i<j; i++)
  7. if(re.test(els[i].className))a.push(els[i]);
  8. return a;
  9. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.