You can use the jQuery .filter() method, which allows, among other things, a selector argument to filter selected nodes in a jQuery object.
var filtered = s.filter(':lt(2)');
Note that this does not change the original value of s , so you will have your entire div in s and your filtered div in filtered .
Alternatively, as you said and discussed in the comments, you can use Array.prototype.slice .
var sliced = $(s.slice(0,2));
This is technically faster than .filter() . However, this may also make your code less readable / understandable. The increase in productivity can also be extremely small if you do not perform this operation many thousands of times or more in a very short period of time.
Readability and performance is a battle often battled in programming, and ultimately you are the only one who can decide which one will win for your own code.
source share