Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9194961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:31:54+00:00 2026-06-17T21:31:54+00:00

Possible Duplicate: Focus and blur jQuery events not bubbling var default_input_value = null; jQuery(‘body’).on(‘focus

  • 0

Possible Duplicate:
Focus and blur jQuery events not bubbling

var default_input_value = null;
jQuery('body').on('focus focusout', 'input[type="text"]', function(event){
    if(event.type === 'focus'){
        default_input_value = jQuery(this).val();
        jQuery(this).val('');
    }else if(event.type === 'focusout')
        if(jQuery(this).val().length === 0)
        jQuery(this).val(default_input_value);
    }
);

This code simply does not respond to the event.
P.S.
it is important that there would be input[type="text"], because jQuery focus also fires on checkbox in some situations….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:31:55+00:00Added an answer on June 17, 2026 at 9:31 pm

    Under .on() jquery document, there is a description:

    The focus and blur events are specified by the W3C to not bubble, but jQuery defines cross-browser focusin and focusout events that do bubble. When focus and blur are used to attach delegated event handlers, jQuery maps the names and delivers them as focusin and focusout respectively. For consistency and clarity, use the bubbling event type names.

    Hope this would be useful.

    And you can try this code:

    var default_input_value = null;
    jQuery('body').on('focusin focusout', 'input[type="text"]', function(event){
        if(event.type === 'focusin'){
            default_input_value = jQuery(this).val();
            jQuery(this).val('');
        }else if(event.type === 'focusout'){
            if(jQuery(this).val().length === 0)
            jQuery(this).val(default_input_value);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to select an element that has focus on it with jQuery
Possible Duplicate: Using jQuery to test if an input has focus I need to
Possible Duplicate: Javascript event handler on body but not on input I wrote a
Possible Duplicate: Focus input field with JQuery without selecting current value text Using the
Possible Duplicate: Event listener in Java without app having focus? (Global keypress detection) I
Possible Duplicate: Crash on ListView.removeFooterView(View) How is it possible to get a null pointer
Possible Duplicate: input focus outer glow How do I do this in CSS? On
Possible Duplicate: Jquery Unfocus Is there a way to deselect/unfocus an input field using
Possible Duplicate: C# and SendMessage (keys) is not working I am writing an application
Possible Duplicate: Binding dynamically created elements in jQuery Is there a way I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.