javascript dataset code example
Example 1: dataset js
for javascript :
webappData.getAttribute('data-id');
document.querySelector('#elementId').dataset.id = 'value';
for jquery :
$(element).attr('data-key', 'value');
Example 2: javascript get data attribute value
const article = document.querySelector('#electric-cars');
article.dataset.columns
article.dataset.indexNumber
article.dataset.parent
Example 3: accèder data-id javascript
<article
id="voitureelectrique"
data-columns="3"
data-index-number="12314"
data-parent="voitures">
...
</article>
var article = document.getElementById('voitureelectrique');
article.dataset.columns
article.dataset.indexNumber
article.dataset.parent
Example 4: javascript dataset
<div id="user" data-user-id="2" data-user-date-of-birth="03/03/1993">
<p> Hello ! </p>
</div>
const user = document.getElementById('user')
console.log(user.dataset.userId)
console.log(user.dataset.userDateOfBirth)