I need to wrap up an array of elements into a jQuery object as if they were selected so that I can call various jQuery actions on them.
I'm looking for a function like foo
below that accepts an array of elements and returns a jQuery object with them in it.
var elements = [element1, element2, element3];
$(foo(elements)).click(function() {
...
});
Can someone shed some light on this?
Thanks much.
Just do
$(elements).click( function(){ ... });
if your elements are actual references to the DOM
demo: http://jsfiddle.net/gaby/dVKEP/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With