Answers for "how to set data-id value in jquery"

1

set data-id value jquery

$('#mydiv').attr('data-myval', 'Undertaker'); // sets 
 $('#mydiv').attr('data-myval'); // gets
Posted by: Guest on October-27-2021
0

jquery get data-id

const dataId = $('#elementId').attr("data-id");
Posted by: Guest on August-13-2020
0

jquery get data-id

$(this).data("id") // will return the number 123
Posted by: Guest on July-18-2021
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

Code answers related to "Javascript"

Browse Popular Code Answers by Language