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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:58:27+00:00 2026-06-11T05:58:27+00:00

I am implementing my own ‘tooltip’ where it creates a new div element every

  • 0

I am implementing my own ‘tooltip’ where it creates a new div element every time you hover over it and removes it on hover out. The code below is stripped down from what I use but it shows the problem: This piece of code works perfect when a user slowly puts their mouse over and off the $(‘#’ + fieldName) object but when you move your mouse on the object and then quickly pull it off the tooltip does not get removed. Is there a way to improve my code?

I tried implementing a system where I create all the tooltip boxes and hide them, then show them on hover, but it posed the same problem with the mouse moving quickly off the object and the hover out not firing.

$('#' + fieldName).hover(
    function () { /* Create new DOM element */
        /* My ajax stuff here */
        var data = 'test';
        var tooltipBox = $('<div id="' + fieldName + '_tooltip">' + data + '</div>');
        $("body").prepend(tooltipBox);
    },
    function () { /* Remove Tooltip from DOM */
        $('#' + fieldName + '_tooltip').remove();
    }
);

Answer:

With help from Robert Koritnik and sajawikio:

If you need to make tooltips on hover with AJAX calls in the hover you can do a small hack to make it work.

var callingAjax = false;
var removeTooltip = false;
$('#tooltip').hover(
     function() {
          callingAjax = true;
          $.post(.. {
              callingAjax = false;
              /* do stuff */
              if(removeTooltip)
                   /* code to remove tooltip */
              removeTooltip = false;
          });
     },
     function() {
          if(callingAjax) 
              removeTooltip = true;
          else
              /* code to remove tooltip */
     }
);
  • 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-11T05:58:28+00:00Added an answer on June 11, 2026 at 5:58 am

    Your code works

    I’ve put your code in a JSFiddle and it works, so you must have some other problem. I can move mouse as fast over the link as possible but tooltip gets removed every single time.

    I’m using Chrome. What’s your drug?

    Note: The only difference between my code in the JSFiddle and yours is that I’ve used append and you’ve used prepend. I’ve changed that for obvious reasons. Try changing it and you’ll see why. But it works in both ways.

    Note 2: Actually if you change append to prepend it actually simulates fast mouse movement, because the moment when an object is pre-pended, mouse hovers out of the link. So instead of moving the mouse as quick as possible, move the element to simulate the same behaviour.

    The actual problem

    The problem is that you’re executing other things in hover before creating tooltip. It doesn’t really matter whether that’s an Ajax call. It may be anything that is asynchronous so Javascript thread can execute next functions. And if that executes longer than you stay on the element, your mouse out want’s to remove something that hasn’t been created yet (and will be later on).

    Two possible solutions:

    1. Add your tooltip first and then execute other stuff.
    2. Defer Ajax call after hover event executes.

    Warning

    I would strongly suggest to not execute ajax code in hover event because you may fire lots and lots requests. Actually, more than browser can handle. If you must execute ajax request on hover then do it this way: hover fires and prepares a function call to be executed right after it, but that function will only issue an Ajax call if one is not being in progress already:

    // variable outside of hover closures
    var ajaxExecuting = false;
    
    // code to put within your hover handler
    setTimeout(function() {
        if (!ajaxExecuting)
        {
            ajaxExecuting = true;
            // do your AJAX stuff
        }
    }, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm just trying out the new font-face feature in css3 for implementing own ttf/otf
I am implementing my own fsm to parse a file. I am new to
Im implementing my own proto in Java, it will use a heartbeat over a
For a videogame I'm implementing in my spare time, I've tried implementing my own
Consider we are implementing our own thread with lot of autoreleased object. Is it
I'm implementing my own Content Provider because I'm gonna synchronize my database with a
I've been implementing my own version of a red-black tree, mostly basing my algorithms
I'm implementing my own NSBitmapImageRep (to draw PBM image files). To draw them, I'm
I'm implementing my own double-buffering for a BufferedImage in a JPanel so that I
I'm implementing my own matrix math for an OpenGL application. So far, things are

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.