6

Possible Duplicate:
How does jQuery .data() work?

 <script>
    $("div").data("test", { first: 16, last: "pizza!" });
    </script>

I thought, via Google Chrome Developer Tools, i could see something like:

<div first="16" last="pizza!"></div>

but i couldn't.

How exactly does .data() attach data to elements? Is there a chance i can see/inspect data without invoking .data() method?

Community
  • 1
  • 1
DrStrangeLove
  • 11,227
  • 16
  • 59
  • 72
  • 1
    Have a look at the non-minimized code http://code.jquery.com/jquery-1.7.js and search for `data:`. It's quite good commented. Also if jquery would actually place those attributes on the node. It would use `data-first` and `data-last`. Which allready works to prefill data values like `data-placeholder="foo"` would init `.data('placeholder')` as `foo`. – Yoshi Nov 14 '11 at 12:12
  • You are looking for this post http://stackoverflow.com/questions/772608/jquery-loop-through-data-object – Niels Nov 14 '11 at 12:13
  • Why would you want to do that.. You are breaking the abstraction then – Ankur Nov 14 '11 at 12:15

1 Answers1

0

From this question: How does jQuery .data() work? it seems jQuery holds an internal cache-object to store the items. From that answer you'll also see it's possible to do this via the javascript-console through:

 $.cache

which will give you all of the values, if I'm not mistaken.

Community
  • 1
  • 1
nillls
  • 625
  • 4
  • 11
  • 1
    You should not answer a question by just repeating another answer. If a question can be answered this way, it is a duplicate and should be closed as such. – Felix Kling Nov 14 '11 at 12:41