如何从jquery对象中删除dom元素 [英] How to delete dom element from jquery object
本文介绍了如何从jquery对象中删除dom元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的对象中删除一个特定的类,因为我的要求是在显示内容之前删除该dom数据。我已经编写了一个示例代码,但却无法理解为什么它不起作用。我jquery的删除也无法正常工作。请帮我解决。提前致谢
i want to delete a particular class from my object as my requirement is to delete that dom data before displaying content. I have written a sample code but not able to get why that is not working. I jquery's remove is also not working. Please help me to get it solve. Thanks in advance
<html>
<head>
<title>test</title>
<script type="text/javascript" src="jquery-1.5.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// complete html
var test;
test = $('#issue_detail_first_row').html();
var x = $(test).find('#issue_detail_nav').not('.p1');
$('#sett').html(x);
});
</script>
</head>
<body>
<div id="issueDetailContainer">
<div id="issue_detail_first_row">
<div>
<div id="issue_detail_nav">
<div>test</div>
<div id="gett">
<div class="p1">
this content need to be deleted 1
</div>
</div>
<div class="p1">
this content need to be deleted 2
</div>
</div>
</div>
</div>
<br/><br/><br/><br/>
<div id="sett">
</div>
推荐答案
您需要直接从DOM中删除内容。
You need to remove the content from the DOM directly.
$("#issue_detail_first_row .p1").remove();
这将选择 .p1
元素和从DOM中删除它们
That will select the .p1
elements and remove them from the DOM
这篇关于如何从jquery对象中删除dom元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文