I'm trying to make a safari extension that does something if the cursor focus isn't in a text field. However the following code to detect if the focus isn't in a text field does not work.
if ($(document.activeElement).attr("type") != "text"
&& $(document.activeElement).attr("type") != "textarea") {
..do something
}