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
2
votes
2 answers

How to get the $.data() on the option inside the dropdown?

$('#selectSurvey').append(''); $('#selectSurvey').on('change',function(e){ $('#image-here').attr('src',this.data('img')); //wrong }); How do I get the data in Option1 inside…
clintgh
  • 2,039
  • 3
  • 28
  • 44
2
votes
4 answers

Set data attribute to div with jQuery

I am trying to set a data attribute to a div which previously doesn't have any value.
with jQuery, the first method (data) doesn't do anything, however the attr method works correctly. var div =…
Alvaro
  • 9,247
  • 8
  • 49
  • 76
2
votes
3 answers

How to get element data within click function?

Is there a tidier/easier way of getting the checkbox element's 'catNum' value when in its click() function? function createCategoriesList() { var catNames = new Array("First cat", "Second cat", "Third cat"); var catImageURLs = new…
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
2
votes
1 answer

JavaScript: Select elements with data value in range of X and Y

I am creating a calendar and need to be able to select (to show/hide) div.event who's data-dates (which may be string or array, depending on number of days the event appears in) by determining if any of the unix timestamp dates stored there are such…
GhostToast
  • 477
  • 1
  • 6
  • 16
2
votes
2 answers

Unable to Set Element Attribute Using jQuery data()

I'm having trouble updating elements from JavaScript. My project is fairly complex but here's a tiny piece of it: myWebService(/*...*/) .done(function (result) { var newRows = $(rows).clone(); $('#drop-placeholder').after(newRows); …
Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
2
votes
1 answer

iterate through jquery data() objects and push them into another data() object (array)

How can I push an object into a jquery data() object that is an array. I want to end up with the data property numbers containing an array of objects, that I acquire by looping through some html of a particular class. I don't understand how I can…
1252748
  • 14,597
  • 32
  • 109
  • 229
2
votes
1 answer

Get particular row data from jquery datatable

I want to get a particular row data from jQuery data table. Can anyone help me to get the record with first column id? function showchnldetail(val) { var oTable = $('#example').dataTable(); var aData = oTable.fnGetData(val); if (null !=…
user1951007
  • 235
  • 1
  • 11
  • 19
2
votes
7 answers

How Store and Disable Event of another element Temporary

I am looking for a way to manage the events. I have a hover function for element A, and click function for element B. I want to disable A`s hover function temporary while the second click of B. I am looking for a way that not necessary to rewrite…
Micah
  • 4,254
  • 8
  • 30
  • 38
1
vote
2 answers

jquery data returns 'undefined'

I'm trying to store some data in DOM Elements ($.cache) on my plugin but I am facing some problem as mentioned below... $(_buelement).data('yazi') returns undefined on metodlar.gizle but it works on metodlar.goster where I store the data. In my…
Lupus
  • 1,519
  • 3
  • 21
  • 38
1
vote
1 answer

jQuery data() and resize() to change src attribute

I'm working on a script uses jQuery's data() function and HTML5 data attributes to dynamically switch an image's src attribute based on a media query. The idea behind this is to serve a lo-fi image by default (optimized for mobile), and serve a…
ryanve
  • 50,076
  • 30
  • 102
  • 137
1
vote
1 answer

jQuery filter by data property

I've the following snippet, which must return objects by some condition, but I got this error: Uncaught TypeError: Cannot read property 'obj1' of undefined. However, I see this data attr in the li object using console. for(var i = 0; i < 15;…
NisuSan
  • 197
  • 1
  • 13
1
vote
0 answers

jQuery Datatable - Export and Email

I am able to export jQuery Datatable data to Excel/PDF or CSV format but does it is possible to send this report as attachment or can we parse the data and draft a mail including datatable as Mail body? I have tried to parse using …
Krishnakant
  • 1,453
  • 3
  • 18
  • 30
1
vote
0 answers

Expando vs jQuery data

I'd like to know if there's any reason to use jQuery's data over expando properties. I'm converting a script that's currently using multiple event listeners to use only one listener on parent object, and wish to read arbitrary data objects from the…
Bharel
  • 23,672
  • 5
  • 40
  • 80
1
vote
0 answers

How can I select elements on data-values that have been added dynamically?

I'm coding a calendar based system. It is displayed as a table. One event can occupy several different table cells, and I want to make all cells of a single event highlight on hover. I have done this several times before, but I am facing a new…
jumps4fun
  • 3,994
  • 10
  • 50
  • 96
1
vote
1 answer

How to copy events from one group to another?

How can I copy events from one group to another? Html (note that .view has no event on purpose),
edit delete
Run
  • 54,938
  • 169
  • 450
  • 748
1 2
3
9 10