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

  • Home
  • SEARCH
  • 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 887323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:12:45+00:00 2026-05-15T13:12:45+00:00

I am using jQuery to show and hide a div by adding/removing a class

  • 0

I am using jQuery to show and hide a div by adding/removing a class to it.

$('input').focus(function(){
    $(this).parents('.row').addClass("linksdiv");
}).blur(function(){
    $(this).parents('.row').removeClass("linksdiv");
});

It works quite well when focusing on inputs, but if I click a link in linksdiv it loses focus and the div disappears. Would it be better to use show() and hide() for the linksdiv than to depend on css?

Would that allow the div to be clickable when inputs are focused? Or is there a simple work around to keep linksdiv from losing focus when clicked but still have it disappear on blur?

Thanks again in advance! You folks are fantastic!

I am sorry I couldn’t describe very well what i was trying to do this is it http://jsfiddle.net/Zw5c2/5/ Thanks Patrick for the resource!

  • 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-15T13:12:45+00:00Added an answer on May 15, 2026 at 1:12 pm

    @Nick is right, there won’t be a clean solution.

    One possibility is to delay the code in your blur so that your link’s click handler has a chance to send the focus back to the input.

    http://jsfiddle.net/Zw5c2/

    var lastInput;
    var timeout;
    $('input').focus(function() {
        var $th = $(this);
        lastInput = $th;
        clearTimeout(timeout);
        $th.parents('.row').addClass("linksdiv");
    }).blur(function() {
        var $th = $(this);
        timeout = setTimeout(function() {
            lastInput = null;
            $th.parents('.row').removeClass("linksdiv");
        }, 150);
    });
    
    $('.link').click(function() {
        lastInput.focus();
        // run your code for the link
    });
    

    Another solution may be to make it so that the link is actually an input. Just style it to make it look like a link, and prevent any change to the text.

    http://jsfiddle.net/Zw5c2/1/

    Neither solution is perfect.

    A change to implementation may be better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this show/hide DIV code in my project: http://papermashup.com/demos/jquery-show-hide-plugin/ Currently, after you
I am using jQuery to show/hide a div container (#pluginOptionsContainer), and load a page
I'm using this jquery code to show and hide divs on my page. As
i'm using jquery toggle to show/hide a div on different links. It shows/hides them
Im trying to show/hide a div using jquery when a link gets clicked. I
Possible Duplicate: How to show/hide a div on mouseover using jquery? I have a
I am using JQuery to hide/show a div depending on the selected value of
Possible Duplicate: How to show/hide a div on mouseover using jquery? I have a
I'm using .NET 4 and JQuery to show/hide Div's depending on what's selected from
Using jQuery I am trying to create a function to show and hide the

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.