开发者

How can I get the ID of any element clicked within the $(document) in jQuery/js?

开发者 https://www.devze.com 2023-02-18 08:16 出处:网络
$(document).click(function(e){ alert(e.target); }); That alerts [Object HTMLDivElement], is there another variable with the开发者_运维问答 ID of the object?alert($(e.target).attr(\"id\"));
$(document).click(function(e){
     alert(e.target); 
});

That alerts [Object HTMLDivElement], is there another variable with the开发者_运维问答 ID of the object?


alert($(e.target).attr("id"));

or

alert(e.target.id);
0

精彩评论

暂无评论...
验证码 换一张
取 消