How to get the data-id attribute?

后端 未结 15 2468
青春惊慌失措
青春惊慌失措 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条回答
  •  囚心锁ツ
    2020-11-21 23:39

    Important note. Keep in mind, that if you adjust the data- attribute dynamically via JavaScript it will NOT be reflected in the data() jQuery function. You have to adjust it via data() function as well.

    link
    

    js:

    $(this).data("id") // returns 123
    $(this).attr("data-id", "321"); //change the attribute
    $(this).data("id") // STILL returns 123!!!
    $(this).data("id", "321")
    $(this).data("id") // NOW we have 321
    

提交回复
热议问题