tags:

views:

28

answers:

2

Hi, my existing code as follows

$('#'+ContainerId).find('img').each(function(){
    // ...
});

I want to crate a div element on the fly and append this existing img to this new created div element. Result must be like this which I want

<div style="text-align:center"><img src=".." /></div>
+1  A: 
$('<div/>', {
    css:   {
        'text-align':   'center'
    }
}).append($('#'+ContainerId).find('img'));

Ref.: $(), .append()

jAndy
thank you for your reply.
Kerberos
A: 

You can use wrap(), and you don't even need each():

$('#'+ContainerId).find('img').wrap('<div style="text-align:center"></div>');

Example: http://jsfiddle.net/AndyE/WyXFb/

Andy E
thank you very much. it works perfectly.
Kerberos