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 :: javascript style guide 
Javascript :: how to get current template in vuejs 
Javascript :: javascript store value in array 
Javascript :: create node js server 
Javascript :: angular implementing Validator 
Javascript :: string remove last two characters javascript 
Javascript :: jquery global variable 
Javascript :: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import 
Javascript :: react router how to send data 
Javascript :: remove beginning of base64 javascript 
Javascript :: random color 
Javascript :: array with unique values javascript 
Javascript :: how to check if input is string javascript 
Javascript :: json deep dot 
Javascript :: document on click not working 
Javascript :: nodejs process code 
Javascript :: javascript export to pdf 
Javascript :: live search javascript 
Javascript :: handle onchange react 
Javascript :: get nearest location based on latitude and longitude javascript 
Javascript :: jquery datepicker 
Javascript :: react got error need to enable javascript 
Javascript :: babel-polyfill whatwg-fetch 
Javascript :: jquery close 
Javascript :: javascript beginner 
Javascript :: ssr full form in nextjs 
Javascript :: javascript change color 
Javascript :: javascript to camelcase 
Javascript :: feet to cm javascript 
Javascript :: how to import npm module 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =