Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I group jQuery objects without using selectors?

Tags:

jquery

wrapall

The jQuery.wrapAll function takes a dom subtree and wraps it around a jQuery object. I want to do that but without aquiring the target jQuery object via selector: I have a bunch of references to jQuery wrapped DOM elements and I want to apply wrapAll to all of them. Is it possible to do it without assigning a common class and selecting them through the class?

like image 452
Paralife Avatar asked Jan 17 '12 18:01

Paralife


1 Answers

You can add elements to a jQuery object using the add function. add accepts a selector (adds matching elements), a raw DOM element (adds it), an HTML fragment (creates the element(s) and adds them), and a jQuery object (adds all of the elements in it). That last probably matches what you're looking for.

like image 58
T.J. Crowder Avatar answered Sep 28 '22 18:09

T.J. Crowder