Check out example codes for "jquery set data attribute value". It will help you in understanding the concepts better.

Code Example 1

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

Code Example 2

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>

Code Example 3

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


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

Learn ReactJs, React Native from akashmittal.com