How to get the data-id attribute?

后端 未结 15 2491
青春惊慌失措
青春惊慌失措 2020-11-21 23:29

I\'m using the jQuery quicksand plugin. I need to get the data-id of the clicked item and pass it to a webservice. How do I get the data-id attribute? I\'m using the .

15条回答
  •  旧时难觅i
    2020-11-21 23:43

    To get the contents of the attribute data-id (like in link) you have to use

    $(this).attr("data-id") // will return the string "123"
    

    or .data() (if you use newer jQuery >= 1.4.3)

    $(this).data("id") // will return the number 123
    

    and the part after data- must be lowercase, e.g. data-idNum will not work, but data-idnum will.

提交回复
热议问题