How can I get the ID of an element using jQuery?

后端 未结 19 2833
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 11:57

Why doesn\'

19条回答
  •  借酒劲吻你
    2020-11-22 12:19

    Important: if you are creating a new object with jQuery and binding an event, you MUST use prop and not attr, like this:

    $("

    ",{ id: "yourId", class: "yourClass", html: "" }).on("click", function(e) { alert($(this).prop("id")); }).appendTo("#something");

提交回复
热议问题