Download the X Distribution File.
xGetElementsByClassName(sClsName[, oParentEle[, sTagName[, fnCallback]]])
// xGetElementsByClassName r7, Copyright 2002-2011 Michael Foster (Cross-Browser.com) // Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL function xGetElementsByClassName(c,p,t,f) { var r=[], re, e, i, l; re = new RegExp("(^|\\s)"+c+"(\\s|$)"); // var e = p.getElementsByTagName(t); e = xGetElementsByTagName(t,p); // See xml comments. for (i=0, l=e.length; i<l; ++i) { if (re.test(e[i].className)) { r[r.length] = e[i]; if (f) f(e[i]); } } return r; }
toys - Index of all X demos.
function xGetElementsByClassName2(c,p,f) // test implementation { var e, i, r = new Array(); if (!p) p = document; if (document.evaluate) { var x = document.evaluate(".//*[contains(concat(' ', @class, ' '), ' " + c + " ')]", p, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); for (i = 0; i < x.snapshotLength; i++) { r[r.length] = x.snapshotItem(i); if (f) f(x.snapshotItem(i)); } } /* else if (p.getElementsByClassName) { // FF3 ? r = p.getElementsByClassName(c); } */ else { var re = new RegExp("(^|\\s)"+c+"(\\s|$)"); e = p.getElementsByTagName('*'); // not for IE5 for (i = 0; i < e.length; ++i) { if (re.test(e[i].className)) { r[r.length] = e[i]; if (f) f(e[i]); } } } return r; }
By your use of X and/or CBE and/or any Javascript from this site you consent to the GNU LGPL - please read it. If you have any questions about the license, read the FAQ and/or come to the forums.
Forum support is available at the X Library Support Forums.
Cross-Browser.com is the home of X - a cross-browser Javascript library, and many demos, applications, articles and documentation.
If you are using X, XC or anything from this site, show off your work by posting a link in the X Showcase forum.