Answers for "get item by data attribute value javascript"

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

how to can i get custom data attribute value in javascript

example <button data-keyname = "a'></button>

let variable = element.dataset.keyname;
or
let varibale = element.['keyname'];
or
let variable = element.getAttribute('data-keyname');
Posted by: Guest on December-31-2020

Code answers related to "get item by data attribute value javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language