1

This is really weird to me. Why does $("element").data(.....); work but not jQuery.data(....);?

http://jsfiddle.net/Rdh2e/6/

According to the docs here: http://api.jquery.com/jQuery.data/

you should be able to use jQuery.data to attach data to elements as well....

Am I doing something horribly wrong?

LazerSharks
  • 3,089
  • 4
  • 42
  • 67

1 Answers1

3

$.data() expects the first argument to be a dom element reference not a jQuery wrapper object

element: The DOM element to associate with the data.

jQuery.data($("#kit")[0], "says", "meow");

Demo: Fiddle

when you pass $("#kit") it is passing a jQuery wrapper object, not a dom element reference, you can access the first element in the jQuery wrapper by using the index 0 or like $("#kit").get(0)

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531