mirror of
https://github.com/jquery/jquery.git
synced 2026-02-01 08:55:55 -05:00
Core: Make jQuery objects iterable
Make iterating over jQuery objects possible using ES 2015 for-of:
for ( node of $( "<div id=narwhal>" ) ) {
console.log( node.id ); // "narwhal"
}
Fixes gh-1693
This commit is contained in:
@@ -1538,3 +1538,23 @@ testIframeWithCallback( "Don't call window.onready (#14802)", "core/onready.html
|
||||
equal( error, false, "no call to user-defined onready" );
|
||||
}
|
||||
);
|
||||
|
||||
test( "Iterability of jQuery objects (gh-1693)", function() {
|
||||
/* jshint unused: false */
|
||||
expect( 1 );
|
||||
|
||||
var i, elem, result;
|
||||
|
||||
if ( typeof Symbol === "function" ) {
|
||||
|
||||
elem = jQuery( "<div></div><span></span><a></a>" );
|
||||
result = "";
|
||||
|
||||
try {
|
||||
eval( "for ( i of elem ) { result += i.nodeName; }" );
|
||||
} catch ( e ) {}
|
||||
equal( result, "DIVSPANA", "for-of works on jQuery objects" );
|
||||
} else {
|
||||
ok( true, "The browser doesn't support Symbols" );
|
||||
}
|
||||
} );
|
||||
|
||||
Reference in New Issue
Block a user