Home  >  Article  >  Web Front-end  >  How to remove br in jquery

How to remove br in jquery

WBOY
WBOYOriginal
2022-05-18 16:02:362664browse

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.

How to remove br in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How to remove br

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:

How to remove br in jquery

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn