Check out example codes for "data attribute html". It will help you in understanding the concepts better.

Code Example 1

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

Code Example 2

<p title="I'm a tooltip">This is a paragraph.</p>

Code Example 3

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


Code Example 4

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

Code Example 5

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

Learn ReactJs, React Native from