How do I use the data- attribute to pass values with jQuery?

前端 未结 4 1493
后悔当初
后悔当初 2021-02-19 07:17

I\'d like to know more about using data-* attributes with HTML and its use within jQuery. I\'m simply trying to retrieve data-attribute-name=\"a value\" with .data() and

4条回答
  •  天涯浪人
    2021-02-19 07:58

    The "data-" attribute prefix should be stripped off in your .data() call, so assuming:

    ohai
    

    it would be retrieved via:

    console.log($(".als-item").data("loc-subject"));
    

提交回复
热议问题