Is it possible to view jQuery added data in Chrome

前端 未结 5 1934
青春惊慌失措
青春惊慌失措 2021-02-03 19:37

When creating websites I often use jQuery\'s .data() function to add data to elements.

Is it possible to view all data which is stored with an element in Ch

相关标签:
5条回答
  • 2021-02-03 20:15

    Open the inspector, and into the console, type

    $('<some selector>').data()
    

    and then hit return to evaluate the data() method and show its return value directly.

    There's no need to use console.log unless you're calling it within non-interactive code.

    0 讨论(0)
  • 2021-02-03 20:21

    For this reason, I don't use the $(selector).data() pattern, and, instead I use a more HTML natural $(selector).attr('data-name','value') which adds the values to the actual HTML.

    $(selector).attr('data-name','value') does not work in IE8+ browsers. .data() is preferred. Also, a user defined var such as say: data-name is not an attribute in HTML.

    0 讨论(0)
  • 2021-02-03 20:23

    Chrome Query

    0 讨论(0)
  • 2021-02-03 20:27

    Chrome Query

    Can be found in the Chrome Extensions Webstore and adds another tab to the properties panel in the developer tools.

    0 讨论(0)
  • 2021-02-03 20:36

    Type into the chrome console:

    console.log($('selector').data());
    

    and it will list the data in that element

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