When I run this:
document.activeElement
I get this:
<span id="123" data-caption="ABC">
How to get the content of the data-caption
tag?
In this case, I would like to see the string ABC
.
Many thanks.
When I run this:
document.activeElement
I get this:
<span id="123" data-caption="ABC">
How to get the content of the data-caption
tag?
In this case, I would like to see the string ABC
.
Many thanks.
You can get it in the following way:
document.activeElement.attributes['data-caption'].value;
P.S. consider using a fallback if the element does not have a data-caption
property