data attribute html
snippet in html

data attribute html

user5439

<!-- data-* attritubes can be used on any html element -->
<div data-my-custom-data="true"></div>

js get data attribute

user7992

var element = document.querySelector('.element');
var dataAttribute = element.getAttribute('data-name');
// replace "data-name" with your data attribute name

console.log(dataAttribute);

html javascript find data attribute

user6286

//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')))

select by data attribute

user5730

$('*[data-id="your_id"]');

javascript get data attribute value

user5954

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

accèder data-id javascript

user9843

<article
  id="voitureelectrique"
  data-columns="3"
  data-index-number="12314"
  data-parent="voitures">
...
</article>
var article = document.getElementById('voitureelectrique');
 
article.dataset.columns // "3"
article.dataset.indexNumber // "12314"
article.dataset.parent // "voitures"