The GetAll method is private, in the manipulation module. The code has only a few simple lines, as follows
Copy Code code as follows:
function GetAll (elem) {
if (typeof elem.getelementsbytagname!== "undefined") {
Return Elem.getelementsbytagname ("*");
else if (typeof elem.queryselectorall!== "undefined") {
Return Elem.queryselectorall ("*");
} else {
return [];
}
}
This method is used to get all the child elements of an incoming HTML element from the function name. There are three branches inside
1, first determine whether the Elem has a getElementsByTagName method, such as the use of the getElementsByTagName method to obtain all child elements and then return.
2, getElementsByTagName is not supported to determine whether Elem supports Queryselectorall methods, such as supporting the use of the Queryselectorall method to get element child elements back.
3,getelementsbytagname and Queryselectorall are not supported, return an empty array.
When looking at the code, some doubt, feeling that the second branch is a bit superfluous.
1,getelementsbytagname is the API in DOM Level 2 (earlier), all current browsers should have been supported, and since they are supported, they will not go into the second branch and return directly. The code behind is not all superfluous.
2,queryselectorall is the API (newer) in DOM level 3, IE6/7 not supported.
See here everyone is not also think that the back two branches is redundant? Or is it possible to find a reason that is not superfluous? That is, just find the element elem that meets the following criteria.
"Elem has no getElementsByTagName method, but there are queryselectorall methods."
After many search, the discussion finally found the answer (found by calf students). DocumentFragment satisfies this condition.
Copy Code code as follows:
var frag = document.createdocumentfragment ();
Alert (' getElementsByTagName ' in Frag);
Alert (' Queryselectorall ' in Frag);
The above code in the Ie9/chrome/safari/firefox/opera has popped up false,true.
To this, do not explain.
Note: Several special points of DocumentFragment objects
1,IE6/7/8 has createelement method, other browsers (Ie9/10/safari/chrome/firefox/opera) do not
There is no getElementsByTagName method in 2,ie9/10/firefox/safari/chrome/opera, but there are queryselectorall methods.
Related:
Http://www.jb51.net/article/30352.htm
Https://developer.mozilla.org/en/DOM/document.createDocumentFragment
Https://developer.mozilla.org/En/DOM/DocumentFragment
Http://www.w3.org/TR/DOM-Level-3-Core/core.html