I am building a page with various anchors and form-elements that can be focused and I am wondering how I can get the element that is being focused on currently if something is being focused. I think one way to do it in jQuery is with .is(:focus)
. I'm looking for either a jQuery or vanilla js solution— just something that works.
Here is what I am trying to do in psuedo-code:
if (something is focused){
get the tag name of that which is currently focused and store that in a variable as a string.
}
else {
alert("nothing is being focused on");
}
Also, if you could answer this question, please do: Isn't something always focused? Meaning it is the document / body that is focused when no specific elements are or is nothing focused until done so by the code or user?