tags:

views:

108

answers:

5
+3  Q: 

jquery divs

Hello,

I have an image

<div class='container'>
    <img src='../images.jpg' alt='images' />
</div>

I want to put this image in div with jquery

<div class='container'>
   <div class='some_class'><img src='../images.jpg' alt='images' /></div>
</div>

Tnaks!

sorry, I'd like tu put in this div not onli this images but element also ???

ex:

<div class='container'>
   <div class='some_class'>
       <img src='../images.jpg' alt='images' />
        <strong>text</strong>
   </div>       
</div>
+5  A: 

$(".container img").wrap("<div class=\"some_class\"></div>");

Check out the Wrap documentation

mgroves
sorry, but I can put in this div not onli image but <strong> element also ??? <div class='container'> <div class='some_class'><img src='../images.jpg' alt='images' /> <strong>text</strong></div></div>
Alexander Corotchi
In that case, I'd use something like: $(".some_class").append("<strong>text</strong>"); right after you executed the the Wrap.
mgroves
+1  A: 

If you have an id for the image, you can use wrap:

$("#myimg").wrap("<div class='some_class'></div>");
kgiannakakis
A: 

u can use wrap inner plug in

<script>
$('.myimage').wrapInner('<div><\/div>');
</script>

http://motherrussia.polyester.se/jquery/wrapinner/

Haim Evgi
A: 

You could do this, easy and quick:

$(".container img").wrap("<div class='some_class'></div>");

You can also build the nodes yourself, but with jquery this is a fine answer.

Dave Morgan
A: 
$(".container img").wrap('<div class="some_class"></div>')

There are some great documentation at http://docs.jquery.com/Main_Page

bang