Stop jQuery .data() from converting

前端 未结 1 1470
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-20 17:04

Is there a way to stop the .data() function from converting the data to another type?

For example, with the HTML

Bond, James&
相关标签:
1条回答
  • 2020-12-20 17:42

    Use .attr() instead of .data():

    $("div").attr("data-code-name")
    

    http://jsfiddle.net/dMHS4/1/


    Taken from the jQuery documentation:

    Every attempt is made to convert the string to a JavaScript value (this includes booleans, numbers, objects, arrays, and null) otherwise it is left as a string. To retrieve the value's attribute as a string without any attempt to convert it, use the attr() method

    0 讨论(0)
提交回复
热议问题