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 :: suspense react 
Javascript :: get the most recent records in mongoose 
Javascript :: How to replace a value in localstorage using javascript 
Javascript :: axio post file 
Javascript :: Javascript removing duplicates in array 
Javascript :: react import json 
Javascript :: Update multiple documents by id set. Mongoose 
Javascript :: Disable click for specific elements javascript 
Javascript :: javascript get day 
Javascript :: capacitor.ionicframework.com to apk 
Javascript :: how to reference the bot joining a server in discord.js 
Javascript :: react prevent component from update once mounted 
Javascript :: es6 node 
Javascript :: vue mounted 
Javascript :: js how to round up 2 decimal places 
Javascript :: strict mode in javascript 
Javascript :: counts the duplicates in an array using for loop 
Javascript :: (Unauthorized) not authorized on admin to execute command 
Javascript :: string to json js 
Javascript :: .net mvc javascript function call link 
Javascript :: js assignment operators 
Javascript :: javascript highlight words 
Javascript :: what is 5+5 
Javascript :: javascript replace p tags with new line 
Javascript :: define an unsigned long int js 
Javascript :: node js server 
Javascript :: axios fetch 
Javascript :: preloader js code 
Javascript :: vue js cdn 
Javascript :: example object 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =