Answers for "javascript get data attribute value from element"

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
5

javascript get data attribute value

const article = document.querySelector('#electric-cars');
 
article.dataset.columns // "3"
article.dataset.indexNumber // "12314"
article.dataset.parent // "cars"
Posted by: Guest on April-15-2020

Code answers related to "javascript get data attribute value from element"

Code answers related to "Javascript"

Browse Popular Code Answers by Language