Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery .data not visible in firebug?

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'));     
like image 712
Mustapha George Avatar asked Mar 27 '12 16:03

Mustapha George


People also ask

How to detect if an element is visible using jQuery?

The jQuery .is ( “:visible”) method is used to detect whether a specific element in the page is visible or not. This is a built in method in jQuery, the “:visible” is the CSS selector that selects the specific visible element.

How to find events attached to an element in Firebug?

It can't find every event because there's no standard way to look up what event handlers are attached to an element, but it works with popular libraries like jQuery, Prototype, MooTools, YUI, etc. Show activity on this post. You could use FireQuery. It shows any events attached to DOM elements in the Firebug's HTML tab.

How do I view events bound to an element in Firefox?

Within the Firefox Developer Tools' Inspector panel lists all events bound to an element. First select an element with Ctrl + Shift + C, e.g. Stack Overflow's upvote arrow. Click on the ev icon to the right of the element, and a dialogue opens:

How to Debug events in jQuery?

I also found jQuery Debugger in the chrome store. You can click on a dom item and it will show all events bound to it along with the callback function. I was debugging an application where events weren't being removed properly and this helped me track it down in minutes.


2 Answers

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/

like image 156
Naftali Avatar answered Oct 13 '22 00:10

Naftali


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.

like image 20
benz001 Avatar answered Oct 13 '22 02:10

benz001