David David - 1 year ago 124
jQuery Question

Merging jQuery objects

Is it possible to merge several jQuery DOM objects into one array and call jQuery methods on all of them?




var btn = $('button');
var h3 = $('h3');



This doesn't work. I know I can use the 'button,h3' selector here but in some cases I already have several jQuery DOM elements and I need to merge them so I can call jQuery prototypes on all of them.

something like:


would work. Any ideas?


Solved it. You can do it like this:


I'm going to accept the
suggestion as for pointing me in the right direction.

Answer Source

You could use the add method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download