Answers for "how to change a property from an object in the data attribute of an element via jquery"

3

jquery set data attribute value

//<div id="myElementID" data-myvalue="37"></div>
var a = $('#myElementID').data('myvalue'); //get myvalue
$('#myElementID').data('myvalue',38); //set myvalue
Posted by: Guest on October-23-2019
3

jquery data attribute

/* html */
<a data-number="123">link</a>

/* js */
$(this).attr("data-number") // returns string "123"

$(this).data("number") // returns number 123 (jQuery >= 1.4.3 only)
Posted by: Guest on October-28-2020
0

set data attribute with a string jquery

alert($('#outer').html());   // alerts <div id="mydiv" data-myval="10"> </div>
var a = $('#mydiv').data('myval'); //getter
$('#mydiv').attr("data-myval","20"); //setter
alert($('#outer').html());   //alerts <div id="mydiv" data-myval="20"> </div>
Posted by: Guest on September-18-2020
4

jquery get data attribute

<a data-id="123">link</a>


var id = $(this).data("id"); // Will set id to 123
Posted by: Guest on April-16-2020

Code answers related to "how to change a property from an object in the data attribute of an element via jquery"

Code answers related to "Javascript"

Browse Popular Code Answers by Language