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
0
votes
3 answers

HTML5 way to store/retrieve object's data

what's the HTML5 replacement (pure HTML no jQuery) for the following? $("#blah#").data("key", value); var value = $("#blah#").data("key");
user1514042
  • 1,899
  • 7
  • 31
  • 57
0
votes
3 answers

how to disable jquery data function return value by ref?

somehow getting jquery data() function return an object by ref. it is a way in javascript to point to the object him self without to modify the ref object ? here is my demonstration of the problem :
foxdanni
  • 199
  • 1
  • 19
0
votes
2 answers

javascript: html5 getting and setting data-*

I've used var activeFilter = $('
  • ').data('input-id', 'mycustomId'); $('#container').append(activeFilter); Now I need to get the particular < li > element out of multiple < li > elements in known < ul >. However the obvious selector doesn't…
    Max
    • 1,463
    • 5
    • 19
    • 34
    0
    votes
    1 answer

    Adding jQuery .data() versus adding data-xxx attribute to your elements

    So you can add your html to your document by appending it. $game.append('
    A
    '); or you could: var game = document.getElementById('game'); var div = document.createElement('div'); $(div).data('letter',…
    Jonathan Tonge
    • 1,520
    • 19
    • 25
    0
    votes
    2 answers

    how to keep data in page after reload?

    I have a page which loads a login page, after the user logged in it will load some parts of another file into itself. The problem is that I want to know which button is pressed in the first page and have it in the login page. The first page loads…
    Homam
    • 707
    • 2
    • 9
    • 20
    0
    votes
    3 answers

    Adding arbitary data in Jquery using .data()

    I was trying add arbitrary data while doing this I got following doubts in my mind: How much data I can add, is there any limit? Does it affect in anyway to performance/execution Speed? And what about safety of data, is it safe? Where does these…
    sandip
    • 3,279
    • 5
    • 31
    • 54
    0
    votes
    1 answer

    jQuery .data() assignments work in console print but produces errors

    What is wrong with these jQuery data() assignments? When I wrap the first in a console.log(), it works and prints out the data. But jsbin shows tons of errors that I can't put my finger on? $("body").data("user_information",…
    1252748
    • 14,597
    • 32
    • 109
    • 229
    0
    votes
    3 answers

    setting a variable with jquery data

    I'm trying to make a variable in a function, that I can then redefine using it again in a different function, and I was wanting to use jquery .data to do it but am unsure how. I have this $(".photo").click(function() { var id =…
    loriensleafs
    • 2,205
    • 9
    • 37
    • 71
    0
    votes
    1 answer

    How to add the data in jquery datatable

    I need to add the some filter data(from the conditions) into the jquery data table. How its possible?
    user279
    • 65
    • 3
    • 11
    0
    votes
    1 answer

    Jquery datatable filter by text

    I am using the below code to filter the record from jquery data table.My data table format like this var aDataSet = [['1', 'GOld', 'G-110,G-112,G-123', 'G1-001,G1-005,G1-008'], ['2', 'GOld type 1', 'G1-001,G1-003,G-123',…
    user1951007
    • 235
    • 1
    • 11
    • 19
    0
    votes
    3 answers

    inline jquery data assignment

    I've seen some data accessed in a javascript function like this: $(this).data('js'); In the html, the data is assigned like this.
  • Male
  • Female
  • I've just not seen…
    1252748
    • 14,597
    • 32
    • 109
    • 229
    0
    votes
    4 answers

    Populating form text inputs with data-* data using jQuery

    I've been trying to wrap my head around this particular issue for two days now. I feel like I'm close, but I can't crack it. I have a div with data-* attributes:
    Wesley
    • 301
    • 1
    • 2
    • 8
    0
    votes
    1 answer

    jQuery.data() working only for appended elements?

    In jQuery documentation (jQuery.data()) examples are regarding "data" assigned to elements that are already appended to document, like this