这是我的代码:
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/