Home > Web Front-end > Front-end Q&A > How to delete child elements in td with jquery

How to delete child elements in td with jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2022-05-12 11:01:22
Original
1864 people have browsed it

Method: 1. Use the children() method to obtain the child element object of the td element. This method can return the direct child element of the selected element. The syntax is "td element object.children()"; 2. Use The remove() method can delete the obtained sub-element, and the syntax is "td sub-element object.remove()".

How to delete child elements in td with jquery

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

How to delete child elements in td with jquery

1. Use the children() method to obtain child elements

The children() method returns the selected element All direct child elements of .

Syntax

$(selector).children(filter)
Copy after login

filter Optional. Specifies a selector expression that narrows the search for child elements.

2. Use the remove() method to delete elements

The remove() method removes the selected elements, including all text and child nodes.

This method will also remove the data and events of the selected element.

Grammar

$(selector).remove()
Copy after login

The example is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>123</title>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("td").children().remove();
});
});
</script>
</head>
<body >
<table border="1">
  <tr>
    <td>Cell<i>A</i></td>
    <td>Cell<i>B</i></td>
  </tr>
</table>
<button>移除td子元素</button>
</body>
</html>
Copy after login

Output result:

How to delete child elements in td with jquery

Related video tutorial recommendations: jQuery video tutorial

The above is the detailed content of How to delete child elements in td with jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template