Jquery divs

I have an image

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

I want to put this image in a div using jquery

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

Tnaks!

Sorry, I want tu to put these images not onli in this div, but the element as well.

Example:

<div class='container'>
   <div class='some_class'>
       <img src='../images.jpg' alt='images' />
        <strong>text</strong>
   </div>       
</div>
+3
source share
5 answers

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

Check out the Wrap documentation

+5
source

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

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

u can use wrap the internal connector in

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

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

0
source

You can do it quickly and easily:

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

You can also create nodes yourself, but with jquery this is a great answer.

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

At http://docs.jquery.com/Main_Page

0
source

Source: https://habr.com/ru/post/1712005/


All Articles