If I've attached a number of key-value pairs to a DOM element using .data(), is there any way to iterate them so I can log them in the console? Alternately, is there a way to view this data with a development tool like FireBug? This would be really helpful when debugging a script.
+3
A:
You can call .data()
without any parameters, like this:
console.log($("selector").data());
It'll be logged as an object in the console easy to navigate.
Nick Craver
2010-09-15 00:46:36
Excellent, thanks!
keithjgrant
2010-09-15 00:49:04
Ooh, this even shows events attached to the element, too.
keithjgrant
2010-09-15 00:52:38
@keithjgrant - Yup, use `$.cache` to see the data for all elements, if that helps any.
Nick Craver
2010-09-15 00:59:57