jquery .data not visible in firebug?

丶灬走出姿态 提交于 2019-12-06 20:29:23

问题


I can use the jquery .data attribute and an alert confirms that it worked, but I don't see data attribute in page using firebug.

$('#something').data('foo', 52);        
alert($('#something').data('foo'));     

回答1:


The information put into .data(...) is not a visible DOM attribute.

You can view an object's data by doing console.log($('#something').data());

Demo: http://jsfiddle.net/maniator/pQybU/




回答2:


jQuery doesn't actually add a data attribute as such to the element and so there is nothing in the DOM that firebug can display.

As Neal points out you can log the data to console to verify that it is in fact there.

Alternatively you can install a Firebug extension such as FireQuery (http://firequery.binaryage.com/) to directly display jQuery data in Firebug itself.



来源:https://stackoverflow.com/questions/9893275/jquery-data-not-visible-in-firebug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!