$('. ').is(":focus") Works Differently in Safari, Firefox and Chrome

$('. ').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:

  1. //Editbox was clicked: manages all events, including button clicks.
  2. $('body').on('click', '#editbox', function() {
  3. if ($('.editURL').is(":focus")) {
  4. alert("Textbox has focus!");
  5. return;
  6. }
  7. if ($('.submitURL').is(":focus"))
  8. {
  9. alert("Clicked the Save button!");
  10. return; 
  11. }
  12. if ($('.cancelURL').is(":focus"))
  13. {
  14. alert("Clicked the Cancel button!");
  15. $('#editbox').hide();
  16. return;
  17. }
  18. $('#editbox').hide();
  19. return;
  20. });