Answers for "js data-id"

12

js get data attribute

var element = document.querySelector('.element');
var dataAttribute = element.getAttribute('data-name');
// replace "data-name" with your data attribute name

console.log(dataAttribute);
Posted by: Guest on February-03-2020
0

javascript get data-id attribute

//get data-id attribute in plain Javascript
var element = document.getElementById('myDivID');
var dataID = element.getAttribute('data-id');

//get data-id using jQuery
var dataID = $('myDivID').data('data-id');
Posted by: Guest on July-31-2019
0

set data-id javascript

var d = document.getElementById("test");  //   Javascript
d.setAttribute('data-id' , 'Next');       //
Posted by: Guest on January-11-2021
0

set data-id javascript

$('#test').attr('data-id' , 'Next');   // JQuery
Posted by: Guest on January-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language