使用Javascript或Jquery去除DIV标签 [英] Remove DIV tag using Javascript or Jquery
本文介绍了使用Javascript或Jquery去除DIV标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何删除具有特定值的DIV?
< div value =0class =task_row >< / DIV>
我想删除上面的值为0的div。
<正如Ben Rowe在评论中指出的那样,
value
不是div标签的有效属性。而且jQuery解决方案和使用 getElementsByTagName()
的解决方案都必须遍历一个列表,这对性能不利。我认为创建 id
属性是一个更好的选择: < div id =task_row_0class =task_row>< / div>
然后你可以这样做:
var div = document.getElementById(task_row_+ taskId);
div.parentNode.removeChild(div);
How do I remove a DIV with a specific value?
<div value="0" class="task_row"></div>
I want to remove the above div which has value 0.
解决方案
As Ben Rowe points out in the comments, value
is not a valid attribute of the div tag. And both the jQuery solution and the solution that uses getElementsByTagName()
has to iterate through a list, which is bad for performance. I think that creating an id
attribute instead is a better option:
<div id="task_row_0" class="task_row"></div>
And then you can just do:
var div = document.getElementById("task_row_" + taskId);
div.parentNode.removeChild(div);
这篇关于使用Javascript或Jquery去除DIV标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文