javascript - 使用 jQuery 删除链接图像和其他 div ID

标签 javascript jquery

这是我的代码:

jQuery("#test").after("<a id='clearall' href='#' onclick='jQuery(this).remove(); jQuery('.clearselection').remove;'><img src='clearselection.gif'></a>");

当我尝试此操作时,出现语法错误:

jQuery(this).remove(); jQuery(<---

当我单击链接时,我需要删除链接图像并删除该类 .clearselection 的所有实例。我尝试转义单引号,但这不起作用。任何帮助将不胜感激。

最佳答案

不要使用内联定义点击处理程序,而是使用 jquery 来处理它:

$(document).on("click", "#clearall", function()
{
   jQuery(this).remove(); 
   jQuery('#clearselection').remove(); //btw you were missing the parens here
});

关于javascript - 使用 jQuery 删除链接图像和其他 div ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16111762/

相关文章:

jquery - 在 html 页面内加载动态内容

jquery - 横向时间轴

javascript - 无法在 webgl 中加载纹理

javascript - jquery窗口调整大小不起作用

javascript - CKEditor 5 缺少可用的工具栏项目

javascript - 如何在jquery中的for循环中求和?

javascript - 动态创建元素的事件处理程序?

javascript - iOS Safari 是否支持 storageEvents?

javascript - 调用 setTimeout 是否清除调用堆栈?

javascript - 如何将 qtip2 工具提示移动到另一个元素?