热门关键字:
jquery > jquery教程 > jquery教程 > 如何从jQuery中的DOM中删除元素

如何从jQuery中的DOM中删除元素

265
作者:管理员
发布时间:2021/2/4 14:05:20
评论数:0
转载请自觉注明原文:http://www.jq-school.com/Show.aspx?id=3831
答:使用jQueryremove()方法
您可以简单地使用jQueryremove()方法从DOM中删除元素。此方法将删除匹配的元素以及其中的所有内容。


下面的示例将向您展示如何从DOM中完全删除一个段落。


例试试这个代码»
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Remove Elements from DOM</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            $("p").remove(); 
        });
    });
</script>
</head>
<body>
    <button>Remove paragraph</button>
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
</body> 
</html>




如果您觉得本文的内容对您的学习有所帮助:支付鼓励



关键字:jquery
友荐云推荐