How to get the data-id attribute?

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

    If you are not concerned about old IE browsers, you can also use HTML5 dataset API

    HTML

    My Awesome Div

    JS

    var myDiv = document.querySelector('#my-div');
    
    myDiv.dataset.info // "some info here"
    myDiv.dataset.otherInfo // "more info here"
    

    Demo: http://html5demos.com/dataset

    Full browser support list: http://caniuse.com/#feat=dataset

提交回复
热议问题