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

How to delete td elements in jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2022-12-12 17:55:36
Original
2800 people have browsed it

In jquery, you can use the remove() method to delete the td element. This method is used to remove the selected element, including all text and child nodes of the selected element. The syntax is "td element object.remove( );".

How to delete td elements in jquery

The operating environment of this tutorial: windows7 system, jquery3.6.1 version, Dell G3 computer.

How to delete td elements with jquery

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.

Tip: If you need to remove elements but retain data and events, please use the detach() method instead.

Tip: If you only want to remove content from the selected element, please use the empty() method.

The syntax is as follows:

$(selector).remove()
Copy after login

The example is as follows:

<html>
<head>
<meta charset="utf-8">
<title>123</title>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("td").remove();
});
});
</script>
</head>
<body>
<table border="1">
            <caption>人物信息</caption>
            <tr>
                <th>姓名</th>
                <th>年龄</th>
            </tr>
            <tr>
                <td>Peter</td>
                <td>20</td>
            </tr>
            <tr>
                <td>Lois</td>
                <td>20</td>
            </tr>
        </table><br />
        <button>点击按钮,去除td</button>
</body>
</html>
Copy after login

Output result:

How to delete td elements in jquery

Related video tutorials Recommended: jQuery video tutorial

The above is the detailed content of How to delete td elements in 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
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template