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
6 answers

jquery custom data attribute not working inside div tag

I am using this div code
and trying to print the values like japp.init = function () { console.log($("div").data("role")); …
Harry
  • 4,705
  • 17
  • 73
  • 101
1
vote
2 answers

jquery .data function vs setting data value in html

in jquery if i use $("#my_button").data('my-value', { onClick: function () { my_obj_function(); } }); and in another function i do this my-value.onClick.call() it works. but if i try to set the data attrib in html it not working. i did this in…
Rifky
  • 1,444
  • 11
  • 26
1
vote
3 answers

Store the original parent of a DIV element

I am moving the position (and parents) of a div element using the insertAfter function. Something like this: $('.annotation i').click(function(){ $('.annotation').find('.comment').insertAfter('#container'); }); I would like to know if it is…
Alvaro
  • 40,778
  • 30
  • 164
  • 336
1
vote
2 answers

Is it possible to store information on non-instantiated objects in jQuery/Javascript?

I'm creating HTML markup in Javascript by concatinating string elements. Something like this: var makeButton = function (el) { 'use strict'; var config = el.attr("data-config"), dyn = $.parseJSON(config), hover = false, …
frequent
  • 27,643
  • 59
  • 181
  • 333
1
vote
3 answers

jQuery - select elements containing custom data

I have a couple of elements like

Text

Text 2

I have a difficulties writing a jQuery selector, that will select all…
1
vote
2 answers

jQuery Data Attribute with Prefix Override Object

I have built my own custom jQuery plugin and I'm trying to override the default options using HTML data attributes. I have added a prefix (pager) to each one so my final mark-up is:
Now say I have an…
nfplee
  • 7,643
  • 12
  • 63
  • 124
1
vote
1 answer

.filter() return undefined

I have a problem with .filter() for the data returned from $.get(). $.get(url, function(data){ $(data).filter('[ref=A]').html() // return undefined }); HTML abc If I do $(data).filter('[ref=B]').html()…
Micah
  • 4,254
  • 8
  • 30
  • 38
1
vote
2 answers

jQuery data and objects

I'm trying to write code something like this: $('[id^=myitem_]').data( 'powq', $([ '

Description:
'+$(this).find("input[name=description]").val()+'

', '

Some other data:

' ].join('')) ); As you…
Kolesar
  • 1,265
  • 3
  • 19
  • 41
1
vote
1 answer

Why does jQuery.data behave different from inside jQuery UI options-events?

I am using jQuery v1.8.3 and jQuery UI v1.9.2. I have implemented the Autocomplete widget this way: $('#input_id').autocomplete({ create: function (event, ui) { // Initialize data $(this).data( 'custom', { property1: 'Hello', property2: {…
user12882
  • 4,702
  • 9
  • 39
  • 54
1
vote
1 answer

Can't get the data object with .data(el,'dataname').sublev

I'm storing data with this code. baslat: function(data) { var $bu = $(this).get(0); if(!$.data($bu, "ipucu_secenekleri")){ metodlar.domEkle.apply(this, data); var ipucu_secenekleri =…
Lupus
  • 1,519
  • 3
  • 21
  • 38
1
vote
0 answers

jQuery plug-in data access -- performance hit?

I'm writing a new jQuery plugin. For the guide, I am using their recommendation: (function( $ ){ var methods = { init : function( options ) { return this.each(function(){ var $this = $(this), data =…
Vadym
  • 964
  • 1
  • 13
  • 31
0
votes
1 answer

Saving custom data to dom elements using jquery only once

I am creating dynamic controls using jQuery by reading the query string parameter. These controls can be dragged to lay them in neat manner, after the drop event in drag/drop I would update the position and state of control through hidden field.…
Deeptechtons
  • 10,945
  • 27
  • 96
  • 178
0
votes
0 answers

How to pass variabel $resultGroup to getColumns Yajra Data Tables?

This is the variable that i wanna pass to getColumns function yajra data tables $resultGroup variable I want to datatables to this getColumns Yajra Datatables How i can parsing $resultGroup to getColumns functions in Yajra Datatables ? And the i…
0
votes
1 answer

select2 not working with datatable actions

We are trying to bind select2 to the select box created in datatable action column when processing it shows select2 box but after load end it shows normal box with out select2 effect. We are creating one column in action as dropdown where we will be…
santosh
  • 51
  • 6
0
votes
1 answer

How to set .data() variable inside an ASP script so it can be accessed later?

I am using $.post() to call an ASP script, which among other things has the following code: %>