set data attributes jquery code example
Example 1: set custom data attribute jquery
//set the custom data value
let mainDiv = $('#yourDivId').data('anyName', value);
//access the custom data value
mainDiv.data('anyName');
Example 2: 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>