0

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.

Dan
  • 3,329
  • 2
  • 21
  • 28

1 Answers1

2

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

Aziza Kasenova
  • 1,501
  • 2
  • 10
  • 22