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 :: disable button based on condition angular 
Javascript :: javascript get black or white text base on color 
Javascript :: react prevent form submission on enter key press inside inputs 
Javascript :: Conflicting peer dependency: react@18.0.0 npm WARN node_modules/react 
Javascript :: a.reduce 
Javascript :: reverse string in js 
Javascript :: o que é jsonm 
Javascript :: check time javascript 
Javascript :: redirect after print javascript 
Javascript :: Auto open browser when run dev nextjs 
Javascript :: js get words first letter 
Javascript :: java script login system 
Javascript :: javascript debounce 
Javascript :: jQuery get background image url of element 
Javascript :: how to remove last index of array in javascript 
Javascript :: date js add days 
Javascript :: get localstorage value 
Javascript :: javascript round off 
Javascript :: scroll to element in scrollable div 
Javascript :: how to reverse a string in JavaScript using reduce function 
Javascript :: use jq to update json file 
Javascript :: how to give width through props 
Javascript :: javascript if and statement 
Javascript :: angular go to external url with blank target 
Javascript :: discord js stats command 
Javascript :: vowels Count js 
Javascript :: jquery add to array with key 
Javascript :: react-hook-form file validation 
Javascript :: javascript image to blob 
Javascript :: nextjs getserversideprops 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =