Several extensions and shorthand _javascript techniques for obtaining DOM objects
Source: Internet
Author: User
Referring to the idea of the getelementsbyclassname in Prototype.js, we extend several methods of acquiring objects that can be used frequently in deom operations, which makes it more convenient and more accurate to use the object of acquiring objects:
Document.getelementsbyclassname = function (Classname,obox) {
Applies to getting all HTML elements within an HTML block that contain a particular classname
this.d= Obox | | Document
var children = this.d.getelementsbytagname (' * ') | | document.all;
var elements = new Array ();
for (var II = 0; II < children.length; ii++) {
var child = Children[ii];
var classnames = Child.className.split (');
for (var j = 0; J < Classnames.length; J + +) {
if (classnames[j] = = ClassName) {
Elements.push (child);
Break
}
}
}
return elements;
}
Document.getelementsbytype = function (Stypevalue,obox) {
Applies to getting all HTML elements within an HTML block that belong to a particular type, such as: Input,script,link, etc.
this.d= Obox | | Document
var children = this.d.getelementsbytagname (' * ') | | document.all;
var elements = new Array ();
for (var II = 0; II < children.length; ii++) {
if (Children[ii].type = = Stypevalue) {
Elements.push (Children[ii]);
}
}
return elements;
}
function $ () {
var elements = new Array ();
for (var II = 0; II < arguments.length; ii++) {
var element = Arguments[ii];
if (typeof element = = ' String ')
element = document.getElementById (element);
if (arguments.length = 1)
return element;
Elements.push (Element);
}
return elements;
}
$Cls = function (s,o) {
Return Document.getelementsbyclassname (S,o);
};
$Type = function (s,o) {
Return Document.getelementsbytype (S,o);
};
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.