getElementsByClass
By koooer
from
function getElementsByClass(searchClass,node,tag) {
var classElements = new Array();
if ( node == null )
node = document;
if ( tag == null )
tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
for (i = 0, j = 0; i
How it works
It’s simple. It works just how you think getElementsByClass would work, except better.
Supply a class name as a string.
(optional) Supply a node. This can be obtained by getElementById, or simply by just throwing in “document� (it will be document if don’t supply a node)). It’s mainly useful if you know your parent and you don’t want to loop through the entire D.O.M.
(optional) Limit your results by adding a tagName. Very useful when you’re toggling checkboxes and etcetera. You could just supply “input“. Or, if you’re like me, and you said Good Bye to IE5, you can use the “*� asterisk as a catch-all (meaning ‘any element).
This entry was posted on December 13, 2005 at 3:14 am and is filed under javascript. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
January 4, 2006 at 12:23 pm
The following function is a straightforward generalization of getElements ByClass() that allows to search for the attribute “class” or other useful atributes like “lang” or some custom made attribute that could be useful to organize your own content.
/* Created by 2mdc.com
url: http://www.2mdc.com
more info: http://2mdc.com/blogs/programacion-web/getelementsbyattribute
This is an extension of getElementsByClass by Dustin Diaz: http://www.dustindiaz.com/
*/
function getElementsByAttribute(attribute,name,node,tag) {
//This is the array that stores the data
var results = new Array();
//Set up default values for node and tag
if ( node == null )
node = document;
if ( tag == null )
tag = ‘*’;
var elements = node.getElementsByTagName(tag);
var elements_length = elements.length;
//The required regular expression
var pattern = new RegExp(“(\\b)”+name+”(\\b)”);
//We search for the required elements
for (i = 0, j = 0; i
July 27, 2007 at 5:31 am
Chrome Wheels and Rims
Using certian cleaners can cause your rims to…
November 5, 2007 at 11:18 pm
XRumer 4.0 is the perfect tool for advertisement!
It’s have CAPTCHA recognizer, email verificator, and a lot of other functions…
But. I forgot link to it
Can you give me link to the xrumer description? screenshots, etc.
Thanks
March 17, 2008 at 8:50 pm
https://support.brooklyn.cuny.edu/member.php?u=106
March 23, 2008 at 4:55 am
Do you know if some company use the same marketing concept as Webkinz?
I’m writing a few articles right now and want to get some info and opinions.
September 11, 2008 at 12:39 am
intermittently non-regulatory as belag endlessly viagra periodically scintilla while
February 12, 2009 at 7:35 am
Hello. And Bye.