2

I am adding an id to an element via call to jQuery.data:

$layout.nextAll('.imagepicker').data('imgPickerId', randomnumber);

So my element of a class imagepicker will have [imgPickerId=randomnumbervalue] data attribute added to it.

It seems like there is a problem how I later on look for .imagepicker with exactly this imgPickerId. Where can I lookup which attributes are added to a particular element in a convenient way (excep from js code)? Maybe in firebug somewhere?

P.S. for some reason my "getter code" works in jQuery 1.6 but does not in 1.7. Still I am suspecting data isn't being added to an element and need a way to check it.

Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174

3 Answers3

3

jQuery's data function stores everything in JavaScript, without altering the DOM in any way. I'm afraid you'll have to use code to access it.

A quick Google search also showed me a FireQuery plugin for Firebug, which seems to enable you to see the attached data of your elements. Haven't tried it myself, though, so I can't confirm that.

Update: Tested it, and it works fine! With FireQuery all data of your elements are visible right next to the HTML:

screenshot of FireQuery showing data attributes

mgibsonbr
  • 21,755
  • 7
  • 70
  • 112
3

Have you considered in writing your data in an custom attribute like data-imgPickerID="someID"?
For sure this does not allow you to save huge data but you could inspect it via firebug and since you are only saving an ID it would fit for your needs.
Which is also very cool about the .data() method is you can retrieve your custom attribute from above like so .data("imgPickerID");

mas-designs
  • 7,498
  • 1
  • 31
  • 56
1

data() will save data in memory (of course linked to the elements in your selector), it doesn't write things on the element, so you can't look at that in firebug.

You can pre-populate elements with some data by using the html5 data attibute though

Look at this question for an expanded explanation

How does jQuery store data with .data()?

Community
  • 1
  • 1
Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192