Current location - Quotes Website - Personality signature - Using js to write the method of obtaining HTML tag objects according to class names.
Using js to write the method of obtaining HTML tag objects according to class names.
/*?

*? Get the HTML element corresponding to the class and tag?

*? ClsName: given class name?

*? Tagname: given HTML element, if it is arbitrary? Tagname =' *'?

*?

*/?

Function? GetElementsByClassName(clsName)? {?

var? ClassElements? =? []; ?

selElements? =? Document.getElementsByTagName (tag name); ?

For what? (var? Me? =? 0; ? Me? & lt? selElements.length? i++)? {?

What if? (selElements[i]. Class name? ==? clsName)? {?

class elements[class elements . length]? =? selElements[I]; ?

}?

}?

Return? ClassElements?

}