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 :: delete first character javascript 
Javascript :: js event listener url change 
Javascript :: check the doc name in javascript 
Javascript :: javascript link to go back 
Javascript :: count items in div jquery 
Javascript :: get values form query params in next js 
Javascript :: js format price 
Javascript :: js check if date is today 
Javascript :: react native italic text 
Javascript :: javascript get current time with hours and minutes 
Javascript :: node version not specified in package.json 
Javascript :: js object length 
Javascript :: update node .js 
Javascript :: npm ERR! path node_modules/node-sass 
Javascript :: jquery rotate 
Javascript :: check email regex js 
Javascript :: disable click event jquery 
Javascript :: getelementbyclass 
Javascript :: change firebase region 
Javascript :: trim comma in javascript 
Javascript :: how to insalk react router with npm 
Javascript :: fullscreen electron 
Javascript :: last query prisma 
Javascript :: express set views directory 
Javascript :: session storage 
Javascript :: js check string for pangram 
Javascript :: material ui multiline 
Javascript :: discord.js v13 finish music play 
Javascript :: remove css inline style javascript 
Javascript :: how to convert a string of numbers into an array javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =