jquery this动画化了这个没有id的元素
jquery this animate this element without id
在我的HTML代码中,我有一个div。这个div包括一些对用户的警告。警告被包装在没有ID的div元素中。如果用户单击关闭按钮,它应该删除警告div。
<div id="alarmbox" align="center">
<div>this is warning 1<button onclick="remove_div_of_this_button(this);">x</button></div>
<div>this is warning 2<button onclick="remove_div_of_this_button(this);">x</button></div>
</div>
这是我的JS代码:
function remove_div_of_this_button(thisbutton)
{
thisbutton.parentNode.parentNode.removeChild(thisbutton.parentNode);
}
它运行良好。但是,删除元素最好设置动画,而不是突然删除。如果我只想操作JS,如何用jquery删除div?是否可以在jquery中识别thisbutton
,因为$(thisbutton)不应该在这里工作?
将js从html中分离出来,并将click事件与jquery一起使用。
带有淡出
$(function(){
$('#alarmbox button').click(function () {
$(this).closest('div').fadeOut(1000,function(){
$(this).remove();
});
});
});
Demo
或者尝试向上滑动
Demo2
也许是这样?
function remove_div_of_this_button(thisbutton)
{
$(thisbutton).parent().fadeOut(function() {
$(this).remove();
});
}
相关文章:
- Javascript:表单验证getElementById仅返回第一个id元素
- 如何为每个带有数字的id元素使用Javascript函数
- 使用regex选择ID元素
- Bootstrap Navbar在选择ID元素后未折叠
- JavaScript-更改一组包含特定文本和变量ID元素的链接
- 父页面中的 JQuery 未在部分视图中检测到 id 元素
- ID 元素在作为参数给出时返回
- 当 Javascript 中的 POST ID 元素插入 PDO 时,数据库中没有结果
- 为什么变量值不显示在 id 元素中
- 如何查找 id 元素的文本值
- 使用 ajax 将 id 元素传递给数据库
- 从另一个HTML文件中获取ID元素
- 正在克隆html标记id元素
- 如何在html中循环使用ID元素
- 获取动态生成的id元素的内部文本发送到谷歌分析
- 如何通过tagname检查ID元素
- jQuery滚动到底部的ID元素
- 检查Id元素javascript
- 在我显示一个id元素后,页面跳转到顶部
- 如何在HTML中突出显示当前的id元素