jQuery: get data attribute

后端 未结 5 2284
慢半拍i
慢半拍i 2020-11-27 03:18

In my html I have a span element:

This is a

5条回答
  •  星月不相逢
    2020-11-27 04:20

    You could use the .attr() function:

    $(this).attr('data-fullText')
    

    or if you lowercase the attribute name:

    data-fulltext="This is a span element"
    

    then you could use the .data() function:

    $(this).data('fulltext')
    

    The .data() function expects and works only with lowercase attribute names.

提交回复
热议问题