Introduction:

In this article we will learn how to use wrap() method in jQuery with example.

Description:

jQuery wrap() method is used to wrap specified HTML elements around each selected element. The wrap() function can accept any string or object that could be passed through the $() factory function.

Example of jQuery warp() method

Let's take an example to demonstrate the effect of jQuery warp() method.

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Jquery Tutorials</title>
    <script src="Scripts/jquery-1.8.2.min.js"></script>
    <script>
        $(document).ready(function () {
            $("button").click(function () {
                var content = '<div class="div"></div>';
                $("#destination").wrap(content);
            });
        });
    </script>
   <style>
        .div {
            margin: 5px;
            padding: 2px;
            border: 2px solid #666;
            width: 60px;
        }
   </style> 
</head>
<body>
    <button>Click on any square to wrap the text:</button><br/>
    <div class="div" id="destination">We are going to wrap this text</div>     
</body>
</html>

 

Output:

how to use warp() method in jquery

i hope it will help to you.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like