getElementsBy(attribute, value)

getElementsBy(attribute, value)


I'd like to propose a more useful DOM method then what
getElementsByClassName is supposed to provide (http://www.whatwg.org/
specs/web-apps/current-work/#getelementsbyclassname), replacing both
the need for getElementsByClassName and getElementsByName (http://
www.whatwg.org/specs/web-apps/current-work/#getelementsbyname), while
having a great performance potential when used directly or via
libraries.
Method signature would be:
getElementsBy(attribute: String, value: String, RegExp)
Usage examples:
function getElementsByName(name) {
return document.getElementsBy("name", name);
}
function getElementsByClassName(className) {
return document.getElementsBy("class", className);
}
function getElementsStartingWithId(id) {
return document.getElementsBy("id", new RegExp("^" + id));
}
To actually be able to replace getElementsByClassName,
getElementsBy("class", className) would have to implement the special
case where the class attribute is split by whitespace and matched one
by one.
This makes much more sense to me then adding another
getElementsByAnotherAttribute every few years, especially considering
new attributes like required on input elements (http://www.whatwg.org/
specs/web-forms/current-work/#the-required).
I'd like to get the feedback of this group before trying to push this
out to a few blogs. Also ideas where to actually propose this are
welcome.