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.

Let’s see, Example of jQuery warp() method:

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Example of jQuery wrap method</title>
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.10.2.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>


 Let's check live example

0 comments


Leave a comment

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

You may also like