我有以下的HTML代码
<div name="taskNotificationsDiv">
<div class="notificationCard">
<span class="taskNotificationClose">x</span>
Test
</div>
<hr>
<div class="notificationCard">
<span class="taskNotificationClose">x</span>
Test
</div>
<hr>
<div class="notificationCard">
<span class="taskNotificationClose">x</span>
Test
</div>
<hr>
</div>
我有下面的脚本,当x被点击时,从父元素中移除该容器。
$(".taskNotificationClose").click(function (){
this.parentNode.parentNode
.removeChild(this.parentNode);
return false;
});
我需要的是删除div容器下方的hr线。请有人帮忙看一下,并告诉我应该如何实现。
这里是fiddle链接[Fiddle][1]。
我试过以下代码,尝试找到最近的hr并将其从父元素中删除,但出现了错误。
[1]: https://jsfiddle.net/
var $hr = $(this).next('hr');
this.parentNode.parentNode.removeChild($hr);
感谢您![1]: https://jsfiddle.net/so3k2hpq/ 这是链接地址。