Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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);
Comment

html javascript find data attribute

//javascript get html data attribute
<button data-id="1" >Click</button>
<button data-id="2" >Click</button>
<button data-id="3" >Click</button>
const btns=document.querySelectorAll('button[data-id]');
[...btns].forEach(btn => console.log(btn.getAttribute('data-id')))
Comment

get data attribute javascript

// <div id="element" data-name="john"></div>

const el = document.querySelector('#element')
el.dataset.name // 'john'
Comment

javascript get data attribute value

const article = document.querySelector('#electric-cars');
 
article.dataset.columns // "3"
article.dataset.indexNumber // "12314"
article.dataset.parent // "cars"
Comment

get element with data attribute javascript

const elements = document.querySelectorAll("li[data-id='2']");
Comment

PREVIOUS NEXT
Code Example
Javascript :: js get data from form 
Javascript :: how to convert array to object in lodash 
Javascript :: javascript string includes 
Javascript :: javascript get random line from text file 
Javascript :: Nuxt JS Adding script tag to particular page 
Javascript :: new nextjs project 
Javascript :: javascript alert get text 
Javascript :: componentdidupdate in hooks 
Javascript :: how to always run validators mongoose 
Javascript :: integers to space separated string in javascript 
Javascript :: convert object to boolean javascript 
Javascript :: vue dev server proxy not working 
Javascript :: jquery download image from url 
Javascript :: cheerio load from file 
Javascript :: beautify json in html 
Javascript :: how to pretty formatjson value on terminal ruby 
Javascript :: jQuery CSS Classes 
Javascript :: link script react17 
Javascript :: Jquery trigger change event upon dom ready 
Javascript :: how get checkbox if checked in jquery 
Javascript :: map to array javascript 
Javascript :: factorial of number js 
Javascript :: discord js fetch user 
Javascript :: js exec find all 
Javascript :: search class regex 
Javascript :: add zero in front of numbers javascript 
Javascript :: Capitalise a String 
Javascript :: remove empty element from array js 
Javascript :: js generate random number 
Javascript :: xmlhttprequest get request 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =