Home > Article > Web Front-end > How to delete parent element based on specified element in jquery
In jquery, you can use the unwrap() method to delete the parent element of the specified element. This method can remove the parent element of the selected element, but will keep itself in its original position; the syntax "$( selector).unwrap()".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
In jquery, you can use the unwrap() method to delete the parent element based on the specified element.
The unwrap() method removes the parent element of the selected element, but leaves itself (and sibling elements, if present) in its original position.
Syntax:
$(selector).unwrap()
Note: This method does not accept any parameters.
Example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { $("button").click(function() { $("p").unwrap(); }); }); </script> <style> div { background-color: yellow; } article { background-color: pink; } </style> </head> <body> <div> <p>这是一个div元素中的段落。</p> </div> <article> <p>这是一个在文章元素的段落。</p> </article> <button>移除每个p元素的父元素</button> </body> </html>
Recommended related tutorials: jQuery video tutorial
The above is the detailed content of How to delete parent element based on specified element in jquery. For more information, please follow other related articles on the PHP Chinese website!