Questions tagged [jquery-data]

jQuery `.data` can store arbitrary data associated with the matched elements or return the value at the named data store for the first element in the set of matched elements.

jQuery's .data Store arbitrary data associated with the matched elements or return the value at the named data store for the first element in the set of matched elements.

Example

One short example of use is to set data with `

$("body").data("foo", "bar");

which can later be returned by calling

$("body").data("foo");`, 

which will return "bar".

You can also use .data to return the value of a custom data- attribute. For example, if you have the HTML element

<div id="myDiv" data-info="My Info"></div>`

you can call

$("#myDiv").data('info');

which will return "My Info". Note that .data will not edit or add these attributes, only read.

Resource

140 questions
-1
votes
1 answer

how to set property within property in jQuery data()

If I know that a certain data property exists on an element and it is an object, how can I store something as a new property of that data object? For example, I have this div:
And I'm…
1252748
  • 14,597
  • 32
  • 109
  • 229
-2
votes
3 answers

jQuery data function usage with keywords

My HTML: Download Link I am getting incorrect value for $("#link").data("href") when clicked multiple times. Click Handler: $(document).on("click", "#link", function (e) { var url =…
Joseph
  • 91
  • 1
  • 7
-2
votes
1 answer

Javascript / jQuery function return value empty

Possible Duplicate: jQuery AJAX: return value on success I am trying to load a song list from the YouTube data API and have been successful until I broke it out into it's own function. The problem is with my local variable's value vaporizing when…
user1709730
  • 141
  • 2
  • 10
-3
votes
1 answer

Get each numbered data attribute jquery

HTML
I want to get each of these data-thumb-* attributes with…
sansome
  • 19
  • 1
  • 5
-5
votes
1 answer

why animate() doesn't work well with data()?