Category: >> JavaScript >> Find All Elements By Class Bookmark and Share

<< lastnext >>

Snippet Name: Find All Elements By Class

Description: A function that returns an array of elements based on DOM element, tag, and class name. For example, getElementsByClassName(document, 'tdr', 'error') will return an array of all "td" tags under the document node having the "error" class.

Also see:
» Automatically find location of jav...
» Find first non-numeric character i...
» Regexp: Find and highlight repeate...
» Get every 2nd (or 3rd, 4th, ...) e...
» Grab the last element of an array
» Generate Random Numbers
» Find Symlink Targets
» Super Fast Prime Number Finder
» Find Percentage Function
» Get the computed style of an eleme...
» Dynamically create HTML elements
» Dynamically add and remove elements
» Search array elements for a substr...
» Unset unkown array element
» FLASHBACK: Syntax Elements
» SEQUENCE: Find sequence MAX value
» Date: Find first day of the month
» Find users with deadly privileges
» Find all duplicates in a column
» Find the current URL of the page
» Find Worst Performing Indexes
» Finding a substring in a string
» Find most active SQL in the last h...
» Find Dangerous Users
» Find IP from Hostname
» Filter Empty Array Elements
» Find days between dates #1
» Find All Duplicate Rows

Comment: (none)

Author: CoderZone
Highlight Mode: JAVASCRIPT
Last Modified: December 01st, 2010

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];
	 return (arrReturnElements)
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© | users online: 23