---
title: "why are us the wrap method in JQ?"  
description: "why are us the wrap method in JQ?"  
author: "Ethan Karla"  
published: 2021-07-28  
canonical: https://answers.mindstick.com/qa/93821/why-are-us-the-wrap-method-in-jq  
category: "web application"  
tags: ["web development", "web application development"]  
reading_time: 2 minutes  

---

# why are us the wrap method in JQ?

why are us the wrap [method](https://www.mindstick.com/articles/23411/the-most-effective-method-to-find-the-perfect-small-business-phone-system-for-your-business) in JQ?

## Answers

### Answer by Ravi Vishwakarma

jQuery wrap() is used to wrap the selected HTML in an another html tag. this wrap() can accept any type of data like tagname, string, or object etc.

```
Syntax:$(selector).wrap(wrap data)$(selector).wrap(wrap data, function(index))
```

Example :

```
<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title></title>
    <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
    <script type='text/javascript'>
        $(document).ready(function () {
            $('button').click(function () {
                var content = '<div> </div>'
                $('p').wrap(content);
            });
        });
    </script>
    <style>
        body {
            margin: 10px;
            padding: 10px;
        }
        div {
            background-color: cyan;
            color: white;
            text-align: center;
            font-size:20px;
            height:100px;
            line-height:80px;
        }
    </style>
</head>
<body>
    <button>Click me for wrap the data</button>
    <p>click button for wrap the data in div tag with css</p>
</body>
</html>
```

Output:

![why are us the wrap method in JQ?](https://answers.mindstick.com/questionanswer/8ea700dd-7a1d-4fc1-8fb0-5f083e0efadd/images/878e296c-f7fc-4287-a5d4-d6cc7c5ebda0.png)

\


---

Original Source: https://answers.mindstick.com/qa/93821/why-are-us-the-wrap-method-in-jq

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
