How to get the data-id attribute?

后端 未结 15 2784
青春惊慌失措
青春惊慌失措 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:43

    This piece of code will return the value of the data attributes eg: data-id, data-time, data-name etc.., I have shown for the id

    Click
    

    js:

    $(this).data("id");
    

    // get the value of the data-id -> a1

    $(this).data("id", "a2");
    

    // this will change the data-id -> a2

    $(this).data("id");
    

    // get the value of the data-id -> a2

提交回复
热议问题