$('. ').is(":focus") Works Differently in Safari, Firefox and Chrome
I have a piece of code that creates a popup with a textbox and two buttons. The code tracks which item has focus to trigger proper events. The problem is that the method ($('.').is(":focus")) does not seem to work for <input type=submit>. It works for <input type=text>. Is there a reason for this?
Alternatively, is there a better way to track if a button was pressed in this case? I still want to retain the ability to hide the popup if the user clicks off outside the content box with inputs.
Here is the relevant code:
- //Editbox was clicked: manages all events, including button clicks.
- $('body').on('click', '#editbox', function() {
- if ($('.editURL').is(":focus")) {
- alert("Textbox has focus!");
- return;
- }
-
- if ($('.submitURL').is(":focus"))
- {
- alert("Clicked the Save button!");
- return;
- }
-
- if ($('.cancelURL').is(":focus"))
- {
- alert("Clicked the Cancel button!");
- $('#editbox').hide();
- return;
- }
- $('#editbox').hide();
- return;
- });
-