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
vote
1 answer

jQuery get path from data attribute

I have a small problem, I want to get "path" from data attribute and add to background. HTML
jQuery $('[data-image]').css( { background: "url("+$(this).data('image')+")…
LAron
  • 13
  • 3
1
vote
1 answer

Usage of data() in Jquery Scrolly.js

I am trying to make a parallax plugin for myself and found a simple parallax plugin online called scroll.js : it has a few confusing lines of code though, even multiple checks to the doc's don't help. The jQuery documentation says that the data…
Tenali_raman
  • 2,000
  • 3
  • 18
  • 28
1
vote
3 answers

$.clone() & $.data() strange behaviour

Can someone explain to me why, when I clone an element with jquery .clone(), store it in $(windows).data('myclone') and append this cloned data element to another element, the cloned data present in $(windows).data('myclone') changes? (points toward…
Holmeron
  • 140
  • 1
  • 9
1
vote
1 answer

Why can't I see the data-field on a dynamically created button when clicked?

Edit: Here is a JSFiddle which displays the problem I'm having: http://jsfiddle.net/gyhvpmgy/4/ I have the following function creating a dynamic div: InvalidField.prototype.getMessageStructure = function(){ var div =…
David Moores
  • 1,025
  • 2
  • 9
  • 23
1
vote
1 answer

jQuery event currentTarget dataset

In every jQuery event jQuery provides the currentTarget which is the same as this, but as far as I understand the properties of currentTarget depend on your browser. In chrome I can get event.currentTarget.dataset which gives me the data from the…
Dol
  • 944
  • 3
  • 10
  • 25
1
vote
1 answer

Javascript references and differences in memory allocation

Does the amount of memory allocated to each Javascript reference depend on the object/function its referencing? In other words, if I create a reference to a small object and then create a reference to a large object, how much will the references…
Dol
  • 944
  • 3
  • 10
  • 25
1
vote
4 answers

Adding data attribute value not working

I am trying to add a data attribute with a value to a li, but for some reason its not working. Iv done this before on divs but for some reason its not working correctly now. Here is my jsfiddle http://jsfiddle.net/76MDE/1/ Here is my code.
1
vote
2 answers

Assigning individual keys of object stored in jQuery.data()

I have custom data stored on elements using jQuery.data() method.
Custom data
I know I can access individual keys of the object stored in data-test…
user
  • 17,781
  • 20
  • 98
  • 124
1
vote
0 answers

Holding and hiding lots of data in jQuery.data()

Is there anyway to hide, truncate or limit the json I keep in jQuery Data attributes? I end up having something like the code below which looks a little messy. Considering the data is in $.cache I don't see the point in actually displaying it in the…
Dol
  • 944
  • 3
  • 10
  • 25
1
vote
2 answers

Cannot get jquery data() of parent's parent. Only returns undefined

list:
function: function ok(){ …
clintgh
  • 2,039
  • 3
  • 28
  • 44
1
vote
2 answers

Does storing JSON objects in the class attribute of a tag Validate (XHTML Strict)?

I'm looking at using the jQuery MetaData Plugin. Looks very interesting but...
  • ...
  • does this code validate? update Of course this is…
    qodeninja
    • 10,946
    • 30
    • 98
    • 152
    1
    vote
    2 answers

    jquery data attribute get this element

    I have a view with a lot of images and it render in html like this
    user246340
    • 45
    • 1
    • 7
    1
    vote
    1 answer

    How to read/write data- attributes after they have been dynamically changed by jQuery?

    I am creating a list of items that can be sorted using Mix It Up. I want to have an up and down button on each that increases or decreases the votes for each item and then based on the new votes, moves it up or down in the list. This is all good and…
    John W
    • 199
    • 2
    • 11
    1
    vote
    2 answers

    How to loop in all data having key names including some text

    Assume I have an element like: Click This I want to loop in all data having key names including "param" text. For…
    serefbilge
    • 1,654
    • 4
    • 29
    • 55