Paul
Paul

Reputation: 6176

wrap elements already created (after, before, etc.)?

I've already created my divs in Jquery, but i would like to wrap them all in a div, to work with slideToggle. But i don't see how i can do that, could you please help me?

here's my code :

var $container = $('...(bug)div class="container">')    
                .hide()    
                .appendTo($monid)    
                .fadeIn('slow')    
                .before('..(bug)div class="up">')    
                .after('..(bug)div class="down">');    

and i would like to wrap the divs : "up, down, container" to a new div. Do you have any solution?

Thanks

Upvotes: 2

Views: 320

Answers (2)

FiveTools
FiveTools

Reputation: 6030

var $container = $('div.container')
.hide()
.appendTo($monid)
.fadeIn('slow')
.before('div.up')
.after('div.down');

Upvotes: 0

James Montagne
James Montagne

Reputation: 78690

You can use wrapall.

http://api.jquery.com/wrapAll/

Something like this:

$(".up, .down, .container").wrapAll("<div/>")

Upvotes: 1

Related Questions