Remove the parent element of all <p> elements:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>//from w ww . jav a2 s.c o m <script> $(document).ready(function(){ $("button").click(function(){ $("p").unwrap(); }); }); </script> <style> div{background-color: yellow;} article{background-color: pink;} </style> </head> <body> <div> <p>This is a paragraph inside a div element.</p> </div> <article> <p>This is a paragraph inside an article element.</p> </article> <button>test</button> </body> </html>
The unwrap()
method removes the parent element of the selected elements.
$(selector).unwrap()