这是我的代码:
jQuery("#test").after("<a id='clearall' href='#' onclick='jQuery(this).remove(); jQuery('.clearselection').remove;'><img src='clearselection.gif'></a>");
当我尝试这个时,我收到语法错误:
jQuery(this).remove(); jQuery(<---
当我点击链接时,我需要删除链接图像并删除该类.clearselection的所有实例。我试图逃避单引号,但这不起作用。任何帮助将不胜感激。
答案 0 :(得分:2)
不使用内联定义单击处理程序,而是使用jquery来处理:
$(document).on("click", "#clearall", function()
{
jQuery(this).remove();
jQuery('#clearselection').remove(); //btw you were missing the parens here
});
答案 1 :(得分:0)
替换这个:
onclick='jQuery(this).remove(); jQuery(\'.clearselection\').remove();'