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?
            Asked
            
        
        
            Active
            
        
            Viewed 2,293 times
        
    2 Answers
8
            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.
        T.J. Crowder
        
- 1,031,962
 - 187
 - 1,923
 - 1,875
 
5
            
            
        Yes, add them all to the same object.
obj1.add(obj2).add(obj3).wrapAll('<div class="contentwrapper" />');
        Kevin B
        
- 94,570
 - 16
 - 163
 - 180