reverse jQuery.().prevUntil()
The new jQuery object that is returned contains all previous siblings up to but not including the one matched by the
.prevUntil()
selector; the elements are returned in order from theclosest
sibling to thefarthest
.
ho开发者_如何学Gow to reverse the order from the farthest
to closest
, or maybe, is there any js function to reverse the object returned by .prevUntil()
?
I would say something like:
Array.prototype.slice.call($('.selector').prevUntil('.new_selector')).reverse()
I had this exact same problem and finally found a solution. Had to ditch the prevUntil and prevAll selectors because of the reverse order. Here is what I finally settled on for my solution:
$(".js-readmore").each(function(){
var prevElems = $(this).siblings().not($(this).next());
$(prevElems).wrapAll('<div class="readmore-collapse"></div>');
});
Basically just using the siblings selector and adding a filter to not include next items.
精彩评论