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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:14:56+00:00 2026-05-28T06:14:56+00:00

I have a jQuery code, that is working as I expect it to work

  • 0

I have a jQuery code, that is working as I expect it to work to a certain point.
Here is the fiddle

Three menu items, when hovered over, a black square and additional info appears in the yellow box.
When clicked menu 1 & 3, a green circle appears before the menu.
When clicked menu 2, a search bar appears also and gets in focus with a little bit of delay.

Until this point everything is fine.

What I want is, for example:

-when ‘menu_item’_2 is clicked and I move away the mouse over another item, in the yellow field ‘info_2’ must be shown.

So I should somehow drop the hover after a click has been made.
And when I click another menu_item it should show the corresponding info in the yellow box.

I’m not an expert in jQuery, so maybe the code is must be done some other way.

Anyway, thanks for your help!

$(function() {

$("#search").hover( 
    function() {
        $("#search_info").show();
        $("#arrow").show().css('top', 230);
        $("#fade_search").animate({ opacity: 0.4},50);
    },
    function() {
        $("#arrow, #search_info").hide();
        $("#fade_search").animate({ opacity: 1},50);       
    }).click(function(e) { 
             $("#activated").show().css('top', 232);
             var focusDelay = $("input[type=text]").fadeIn(100);            
                 setTimeout(function(){
                     $(focusDelay).focus();
                 },1000);
             e.preventDefault();
            });

$("#list").hover( 
    function() {
        $("#list_info").show();
        $("#arrow").show().css('top', 205);
        $("#fade_list").animate({ opacity: 0.4},50);
    },
    function() {
        $("#arrow, #list_info").hide();
        $("#fade_list").animate({ opacity: 1},50);

    }).click(function(e) {  show up
             $("#activated").show().css('top', 209 );
             e.preventDefault();
            });

$("#program").hover( 
    function() {
          $("#program_info").show();
          $("#arrow").show().css('top', 255);
          $("#fade_program").animate({ opacity: 0.4},50);
      },
    function() {
          $("#arrow, #program_info").hide();
          $("#fade_program").animate({ opacity: 1},50);

    }).click(function(e) {
             $("#activated").show().css('top', 261 );
             e.preventDefault();
             });
});
  • 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-28T06:14:57+00:00Added an answer on May 28, 2026 at 6:14 am

    I have changed your entire jQuery code. See this jsFiddle for the rework: http://jsfiddle.net/jUHNF/8/

    Note: I assumed you wanted to only show the search box for menu item 2, if that’s not the case, just remove the following:

        else {
            $("input[type=text]").hide();
        }
    

    The code itself should be pretty well commented (maybe a bit too well).

    As you can see I have moved all functions into ONE hover/click event, instead of making them into separate events depending on what menu item you clicked on. The idea here is to keep it clean and simple.

    What if you want to make further changes to your menu clicks (for example make the currently clicked item italic)? Then you would need to make the change in three places, once for each menu event. If you add a new menu item you would need to duplicate the code once more as well… and so on. By making sure that most of your logic can go under the same event you won’t have to duplicate code like this (Don’t Repeat Yourself!)

    Edit: Pasting jsFiddle code for future reference.

        <div id="container">
            <div id="modes">
                <div class="elements" id="list">
                    <a href="">menu_item_1</a>
                </div>
                <div class="elements" id="search">
                    <a class="link" href="">menu_item_2</a>
                </div>
                <div class="elements" id="program">
                    <a href="">menu_item_3</a>
                </div>
            </div>
            <div id="infobox">
                <p id="list_info" class="infobox">
                    info_1
                </p>
                <p id="search_info"class="infobox">
                    info_2
                </p>
                <p id="program_info"class="infobox">
                    info_3
                </p>
            <form method="post" action=""></form>
                <input type="text" name="search_field"
                placeholder="type here" />
            </form>
            </div>
            <div id="arrow"></div>
            <div id="activated"></div>
        </div>
    

    JS:

    $(function() {
        $(".elements").mouseover(
            function() {
                activateMenuItem($(this));
            }
        ).click(function(e) {
            var bulletTop = $(this).position().top + 207; 
            $("#activated").show().css("top", bulletTop);
    
            //turn off the hover function for all menu items
            $(".elements").off("hover"); 
    
            if($(this).attr("id") == "search") {
                 var focusDelay = $("input[type=text]").fadeIn(100);            
                 setTimeout(function(){
                     $(focusDelay).focus();
                 },1000);
            }else {
                $("input[type=text]").hide();
            }
            activateMenuItem($(this)); //do same as on hover
            e.preventDefault();
        });
    
        function activateMenuItem(item) {
                var arrowTop = item.position().top + 205;
                var boxName = "#" + item.attr("id") + "_info";              
                $("#arrow").show().css("top", arrowTop);
                $(".infobox").hide();
                $(boxName).show();
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bit of HTML/JQuery code that only seems to be working for
i have some jquery code here that works fine in firefox but when i
I have this jQuery code that queries an API on a keyup event (via
I have some jquery code that is doing an ajax lookup and returning comma
I have some jQuery code that highlights a link when clicked, and changes the
I have some jQuery code that intercepts links clicked on a page: $(document).ready(function() {
I have some jQuery/JavaScript code that I want to run only when there is
I have the following JQuery code that worked perfect in C#/Asp.net 2.0 to call
I have a simple jQuery code that runs on a web page that has
I have this jQuery datepicker code that initially set the minDate of the datepicker.

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.