jQuery combine multiple elements

后端 未结 2 1257
余生分开走
余生分开走 2021-01-22 08:46

I was experimenting with jQuery and came across a question. Can I use an actual selector with existing element as a combined selector for

相关标签:
2条回答
  • 2021-01-22 09:40

    You could use the jQuery add method:

    $('p').add($div).hover(function(e) { ...
    
    0 讨论(0)
  • 2021-01-22 09:50

    If you have multiple elements to combine you don't wan to do

    $('p').add($div1).add($div2).add($div3).add($div4).add($div5).add($div6) ...
    

    Instead you want to convert a JavaScript array into a jQuery object

    $( $.map([x,y,z], a => [...$.makeArray(a)]) )
    

    Source: Merging jQuery objects

    0 讨论(0)
提交回复
热议问题