Guest User

Untitled

a guest
May 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. function getElementsByClass(searchClass,node,tag) {
  2.  
  3. var classElements = new Array();
  4.  
  5. if ( node == null )
  6.  
  7. node = document;
  8.  
  9. if ( tag == null )
  10.  
  11. tag = '*';
  12.  
  13. var els = node.getElementsByTagName(tag);
  14.  
  15. var elsLen = els.length;
  16.  
  17. var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  18.  
  19. for (i = 0, j = 0; i < elsLen; i++) {
  20.  
  21. if ( pattern.test(els[i].className) ) {
  22.  
  23. classElements[j] = els[i];
  24.  
  25. j++;
  26.  
  27. }
  28.  
  29. }
  30.  
  31. return classElements;
  32.  
  33. }
Add Comment
Please, Sign In to add comment