Jothi Kannan
Jothi Kannan

Reputation: 3358

How to get activeElement's role using jQuery or Javascript

I am trying to get the active element's role attribute. I can get all the other attributes like id, class, title and so on, as below

document.activeElement.title

document.activeElement.class

document.activeElement.tabindex

...but I can't get the role attribute using document.activeElement.role. It throws undefined.

How do I get the role attribute?

Upvotes: 1

Views: 2362

Answers (1)

Leo Jiang
Leo Jiang

Reputation: 26115

document.activeElement.getAttribute('role');

Upvotes: 3

Related Questions