即使在使用.on之后,也只能删除动态创建的div元素的第一个元素

时间:2014-03-15 11:21:26

标签: javascript jquery html

使用jquery 1.10.2 我想删除包含交叉图像的div元素。下面给出的代码仅适用于第一个动态创建的div

$('#cross').on("click",function(e){

  jsPlumb.detachAllConnections($(this).parent());-->detaching jsplumb connections

  $(this).parent().remove();-->cross image is contained in the div element i want to           delete


   e.stopPropagation();
});

1 个答案:

答案 0 :(得分:0)

将侦听器附加到文档。 将#cross替换为您需要的内容。

$(document).on("click","#cross",function(e){

  jsPlumb.detachAllConnections($(this).parent());-->detaching jsplumb connections

  $(this).parent().remove();-->cross image is contained in the div element i want to           delete


   e.stopPropagation();
});