Turn array of jQuery elements into jQuery wrapped set of elements

前端 未结 11 1049
长发绾君心
长发绾君心 2021-02-01 12:39

Is there any elegant way of turning [$(div), $(span), $(li)] into $(div, span, li)?

What I need is a jQuery-wrapped set of elements instead of

11条回答
  •  抹茶落季
    2021-02-01 13:05

    Edit: I thought jQuery supported all Array methods, but nay, so here's a working version of my initial solution, albeit it's a bit odd since I am sticking to the same methods:

    var set; // The array of jQuery objects, 
             // but make sure it's an Array.
    var output = set.pop();
    $.each(set, function (_, item) { 
        return [].push.call(output, [].pop.call(item));
    });
    

提交回复
热议问题