»
EnglishFrenchVietnamese

Print - All Elements By Class Finder - JavaScriptBank.com

Full version: jsB@nk » » All Elements By Class Finder
URL: https://www.javascriptbank.com/all-elements-by-class-finder.html

All Elements By Class Finder © JavaScriptBank.comThis function script will return an array of tags based on DOM element, tag, and class name. For example, getElementsByClassName(document, 'tr', 'info') will return to you an array of all "tr" tags under the document node having the "info" class.

Full version: jsB@nk » » All Elements By Class Finder
URL: https://www.javascriptbank.com/all-elements-by-class-finder.html



JavaScript
<script type="text/javascript">// Created by: Joe Homs | http://bitshaker.com/function getElementsByClassName(oElm, strTagName, strClassName){  var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName); var arrReturnElements = new Array(); strClassName = strClassName.replace(/-/g, "\-"); var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)"); var oElement; for(var i=0; i<arrElements.length; i++){   oElement = arrElements[i];   if(oRegExp.test(oElement.className)){     arrReturnElements.push(oElement);   } } return (arrReturnElements)}</script>