如何删除 html() 中的某些元素?
例如,我有这个 html 链接,
<ul>
<li><a href="#" class="string-comment">Comment</a></li>
<li><a href="#" class="string-delete-needle">Delete</a></li>
<li><a href="#" class="string-publish-needle">Publish</a></li>
</ul>
当您单击 的类时string-publish-needle
,我会将 html 存储在一个变量中,
var html_parents = object_parents.html();
<li><a href="#" class="string-comment">Comment</a></li>
<li><a href="#" class="string-delete-needle">Delete</a></li>
<li><a href="#" class="string-publish-needle">Publish</a></li>
我想删除这个parent
是string-publish-needle
,
<li><a href="#" class="string-publish-needle">Publish</a></li>
所以我只能在下面有一个新的html内容,
<li><a href="#" class="string-comment">Comment</a></li>
<li><a href="#" class="string-delete-needle">Delete</a></li>
我的代码当然不起作用!
$('.string-publish-needle').click(function(e){
var object = $(this);
var object_path = object.attr('href');
var object_parent = object.parent('li');
var object_parents = object.parents('ul');
var html_parents = object_parents.html();
var html_remain = object_parents.html().remove(object_parent);
alert(html_remain);
});