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 511905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:15:54+00:00 2026-05-13T07:15:54+00:00

I am having a bit of trouble combining the HOVER and FOCUS events with

  • 0

I am having a bit of trouble combining the HOVER and FOCUS events with jquery. This is what I had originally:

$("input,textarea").focus(function () {

    $(this).parent().siblings('div.exp').removeClass('hide');
    $(this).parent().siblings('div.exp').addClass('show');

});


$("input,textarea").blur(function (){

    $(this).parent().siblings('div.exp').removeClass('show');
    $(this).parent().siblings('div.exp').addClass('hide');
    if ($(this).val().length <= 0) {
        $(this).siblings('span.warning').removeClass('hide');
        $(this).siblings('span.warning').addClass('show');}

    else {

        $(this).siblings('span.warning').removeClass('show');
        $(this).siblings('span.warning').addClass('hide');
    }


});

Basically, I have a user contact form with rows like the one below:

<div class="row">
  <p><label>Your Name</label><input type="text" name="name" id="name" value=""/><span class="warning">Your name is missing</span></p>
  <div class="exp">Who am I to address?</div> 
</div>

The point of my Jquery code is to bring forth a hidden div (exp) when the user focuses any one input or textarea element as well as checking if the value of said input is not empty when unfocusing (blur) the element. (I haven’t really gotten down to validation yet so checkin for the string length right now is just a temporary filler). Should the element have a string smaller or equal than 0, then span.warning is to be ‘shown’ to the user.

This is all working nicely.
Where I get stuck is the following:

I want to add in hover but without conflicting with focus. My desired final effect is this:

You hover any input or textarea and you get the div.exp to show up (exp is for explanation). You focus any input or area and the div.exp stays there, even if you go about hovering any other inputs or textareas. Should you hover an input that is already focused, nothing should happen.

So, in a nutshell, the focus and hover elements should work ‘independently’ so to speak. Not sure if I made myself clear but oh well, I tried =)

Cheers
G

  • 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-05-13T07:15:55+00:00Added an answer on May 13, 2026 at 7:15 am

    Your code can be significantly shortened by using .hide() and .show() and chaining the events. I posted a demo here.

    $(document).ready(function(e){
     // hide all explanations and warnings
     $('.exp, .warning').hide();
     // add focus, blur and hover events to all inputs & textareas
     $('input,textarea')
      // if focused, show the explanation
      .focus(function(){
       // show explanation on focus (and add a class so the hover function knows not to hide it
       $(this).addClass('focused').closest('.row')
        .find('.exp').show()
        .find('.warning').hide();
      })
      .blur(function(){
       // hide explanation on blur
       $(this).removeClass('focused').closest('.row').find('.exp').hide();
       if ($(this).val().length < 1) {
        // input is empty, show the warning
        $(this).closest('.row').find('.warning').show();
       } else {
        // input is not empty, hide the warning... you might want to add the validation here
        $(this).closest('.row').find('.warning').hide();
       }
      })
      .hover(function(){
       // show explanation when hovered
       $(this).closest('.row').find('.exp').show();
      },function(){
       // hide explanation if the input is not focused
       if ($(this).is(':not(.focused)')) $(this).closest('.row').find('.exp').hide();
      })
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a bit of trouble figuring out what's going wrong with this function.
Having a bit of trouble wrapping my head around this one. I'm sure the
I'm having a bit of trouble with a a function that the mongodb c
I'm having a bit of trouble with jQuery Deferred. I'm using a jQuery ajax
I'm having a bit of trouble iterating and retrieving width() values. $(.MyClass).each( function ()
Having a bit of trouble getting jQuery and Prototype working together. The error console
Having a bit of trouble getting this right... The main objective is to have
I am having a bit of trouble figuring this one out, basically I have
Having a bit of trouble wrapping my head around Qtimer this morning. Here's the
I'm having a bit of trouble finding a nice little jquery plugin that would

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.