单击图像时删除标签?

时间:2013-06-24 14:12:58

标签: javascript jquery html css html5

我正在使用HTML。我添加了一个标签和图片如下:

enter image description here

<{1}} on click需要删除相应的标签。我怎么能这样做?

我在代码下方,但它无效。

red cross mark

1 个答案:

答案 0 :(得分:7)

似乎您对多个HTML元素使用相同的id

将其替换为课程。所以在HTML方面你将拥有class="lbRemove"(而不是id="lbRemove")和jQuery:

$(".lbRemove").click(function(){
    $(this).parent().parent().remove();
});

在HTML中查看the difference between id and class

  • id = name [CS]

      

    此属性为元素指定名称。此名称在文档中必须是唯一的

  • class = cdata-list [CS]

      

    此属性为元素指定类名或类名集。 可以为任意数量的元素分配相同的类名称。多个类名必须用空格字符分隔。