[英]Use classes of dynamically loaded html with Jquery. Continue
$(".content-white").on('click', ".product", function () {
var id = $(".product").attr('id');
alert(id);
});
我怎樣才能獲得一個帶有類產品的元素來獲取它的id?
您可以使用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);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.