Reputation: 12700
I wonder how I can successfully wrap a HTMLCollection into a jQuery/Zepto function.
I have the following same selectors: one in Zepto and the other in vanilla JavaScript wrapped around a Zepto function. The latter, though, doesn't make the Zepto methods available to its nodes.
$('#navigation a');
$( document.getElementById('navigation').getElementsByTagName('a') );
I'd like to make them equivalent.
Edit: I'm using Zepto instead of jQuery and didn't mention it assuming Zepto would behave the same way as jQuery.
Upvotes: 0
Views: 171
Reputation: 8407
You could try the following (untested)
var collection = document.getElementById('navigation').getElementsByTagName('a');
$().add(Array.prototype.slice.call(collection));
From the documentation of add
(see docu) this should be possible to add multiple elements to a current jQuery Object.
$( ... ).add( elements )
One or more elements to add to the set of matched elements.
Upvotes: 1