jquery get data attribute value
snippet in javascript

jquery get data attribute value

user6211

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

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

$(this).data("id") // returns number 123 (jQuery >= 1.4.3 only)

jquery select element with data

user925

$('[data-attribute="value"]');

jquery data attribute

user5750

/* 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)

jquery set data attribute value

user2388

//<div id="myElementID" data-myvalue="37"></div>
var a = $('#myElementID').data('myvalue'); //get myvalue
$('#myElementID').data('myvalue',38); //set myvalue

jquery get data-id

user8504

const dataId = $('#elementId').attr("data-id");

jquery get data attribute

user9803

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


var id = $(this).data("id"); // Will set id to 123