Skip to content
Permalink
Browse files
Simplify getAll helper
  • Loading branch information
markelog committed Dec 24, 2012
1 parent fa3dad3 commit 25712d7
Showing 1 changed file with 3 additions and 13 deletions.
@@ -613,19 +613,9 @@ function cloneCopyEvent( src, dest ) {
}

function getAll( context, tag ) {
var elems, elem,
i = 0,
ret = typeof context.getElementsByTagName !== "undefined" ? context.getElementsByTagName( tag || "*" ) :
typeof context.querySelectorAll !== "undefined" ? context.querySelectorAll( tag || "*" ) :
undefined;

if ( !ret ) {
for ( ret = [], elems = context.childNodes || context; (elem = elems[ i ]) != null; i++ ) {
core_push.apply( ret, !tag || jQuery.nodeName( elem, tag ) ?
getAll( elem, tag ) :
elems );
}
}
var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
[];

return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
jQuery.merge( [ context ], ret ) :

5 comments on commit 25712d7

@fabiomcosta
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this wasn't introduced by your change but what is the reason to try querySelectorAll as a fallback to getElementsByTagName? In which case getElementsByTagName is not supported and querySelectorAll is?

@markelog
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getElementsByTagName is not implemented in documentFragment but qSA is

@fabiomcosta
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the quick response! That's terrible... why did they do this? :/ oh well...

@scottgonzalez
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the WHATWG thread starting here.

@mgol
Copy link
Member

@mgol mgol commented on 25712d7 Aug 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anyone wanting to see that WHATWG thread, the URL is dead, here is a one that works: https://lists.w3.org/Archives/Public/public-whatwg-archive/2013Jun/0207.html

Please sign in to comment.