How to get data attribute value from the element in Javascript?
Question
There is a html as below.
1 | <a id="option1" data-id="10" data-option="21" href="#"> |
I want to get the data-id
and data-option
values while clicking this element.
How to make it happen?
Answer
Solution:
1 | $('#option1').on('click', function () { |
The console log will be 10 and 21.
Reference
This is the end of post