开发者

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 the closest sibling to the farthest.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜