Home > Article > Web Front-end > How to remove br in jquery
Jquery method to remove br: 1. Get the br element, the syntax is "$("br")", which will return a jquery object containing the specified element; 2. Use the remove() function to remove the obtained The br element object is sufficient. The syntax is "br element object.remove()", which will delete the br element and all text and child nodes in it.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
remove() method with jquery removes selected elements, including all text and child nodes.
This method will also remove the data and events of the selected element.
The syntax is:
$(selector).remove()
The example is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>123</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("br").remove(); }); }); </script> </head> <body> <p>这是一个段落。</p><br> <p>这是另一个段落。</p><br> <button>移除所有P元素</button> </body> </html>
Output result:
Related video tutorials Recommended: jQuery video tutorial
The above is the detailed content of How to remove br in jquery. For more information, please follow other related articles on the PHP Chinese website!