AlexC
AlexC

Reputation: 9661

jquery divs

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>

Upvotes: 3

Views: 176

Answers (5)

bang
bang

Reputation: 5221

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

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

Upvotes: 0

Dave Morgan
Dave Morgan

Reputation: 1075

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.

Upvotes: 0

Haim Evgi
Haim Evgi

Reputation: 125486

u can use wrap inner plug in

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

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

Upvotes: 0

kgiannakakis
kgiannakakis

Reputation: 104178

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

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

Upvotes: 1

Matthew Groves
Matthew Groves

Reputation: 26141


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

Check out the Wrap documentation

Upvotes: 5

Related Questions