Why are use the unwrap method in JQ?

1 votes
45 views
Ethan Karla asked 28-Jul-2021 in Web Application by Ethan Karla

Why are use the unwrap method in JQ?

1 Answer

1 votes
Ravi Vishwakarma answered 02-Aug-2021 by Ravi Vishwakarma

jQuery unwrap() is used to unwrap the selected HTML element from parent tag. 

Syntax:
$(selector).unwrap()
    unwarp the parent tag
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 () {             $('#btn1').click(function () {                 var content = '<div> </div>'                 $('p').wrap(content);                 $('p').text('wrap with div tag and style');             });             $('#btn2').click(function () {                 var content = '<div></div>'                 $('p').unwrap();                 $('p').text('unwrap with div and style');             });         });     </script>     <style>         body {             margin: 10px;             padding: 10px;         }         div {             background-color: red;             color: white;             text-align: center;             font-size:20px;             height:100px;             line-height:80px;         }     </style> </head> <body>     <button id='btn1'>Click me for wrap the data</button>     <button id='btn2'>Click me for unwrap p tag form div tag</button>     <p>default stage in p tag</p> </body> </html>

Output

Why are use the unwrap method in JQ?