使用Jquery动态加载的html类。继续

时间:2014-02-01 15:40:36

标签: javascript jquery html

继续提问Use classes of dynamically loaded html with Jquery

$(".content-white").on('click', ".product", function () {
    var id = $(".product").attr('id');
    alert(id);
});

如何获得带有类产品的元素才能获得它的ID?

1 个答案:

答案 0 :(得分:2)

您可以使用this来引用事件处理程序中的目标元素

$(".content-white").on('click', ".product", function () {
    var id = this.id;//this here refers to the dom element which was targeted by the handler
    alert(id);
});

Inside the Event Handling Function