Turn array of jQuery elements into jQuery wrapped set of elements

前端 未结 11 1048
长发绾君心
长发绾君心 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:21

    Say you have an array of jQuery elements:

    let elementList = [$("selector1"), $("selector2"), $("selector3"), ...];
    

    You can simply use the jQuery function ($()) directly on the array which will return a jQuery set:

    let jQuerySetOfElements = $(elementList);
    

提交回复
热议问题