showing results for - "set custom data attribute jquery"
Leah
19 Aug 2016
1//<div id="myElementID" data-myvalue="37"></div>
2var a = $('#myElementID').data('myvalue'); //get myvalue
3$('#myElementID').data('myvalue',38); //set myvalue
Jonah
12 Oct 2016
1alert($('#outer').html());   // alerts <div id="mydiv" data-myval="10"> </div>
2var a = $('#mydiv').data('myval'); //getter
3$('#mydiv').attr("data-myval","20"); //setter
4alert($('#outer').html());   //alerts <div id="mydiv" data-myval="20"> </div>
Alexa
16 Mar 2018
1//set the custom data value
2let mainDiv = $('#yourDivId').data('anyName', value);
3//access the custom data value
4mainDiv.data('anyName');
5
similar questions
queries leading to this page
set custom data attribute jquery