alpenglowtea
alpenglowtea

Reputation: 25

How can I get the id of the focused textbox?

I am creating a Chrome extension and I need to get the id of the selected textbox on the page. I am using Javascript and jQuery

Upvotes: 2

Views: 512

Answers (2)

Shivratna Kumar
Shivratna Kumar

Reputation: 1311

Here is how you can get the id using pure javascript:-

document.activeElement.getAttribute('id')

Upvotes: 1

Francesco Manicardi
Francesco Manicardi

Reputation: 809

You can use the :focus pseudo-class selector. for instance: $("input:focus") will get the focused input.

Upvotes: 1

Related Questions