Leticia Meyer Leticia Meyer - 2 years ago 91
Javascript Question

Find if a textbox is currently selected

How would I find if a textbox (or textarea) currently is in focus? I don't care to know which one it is, I just need to know if one is in focus (has the cursor in it). How would I do this with javascript and jquery?

Answer Source

Since you have found document.activeElement, you can check its nodeName.

if (document.activeElement.nodeName == 'TEXTAREA' || document.activeElement.nodeName == 'INPUT') {
    // ....

Something like that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download