0

Hey there. The situation is like this:

  1. The user clicks a button.
  2. Tooltip pops up.
  3. The user clicks the button again OR the user clicks anywhere outside the tooltip.
  4. The tooltip is removed.

Now I can get either of the events described in step 3 to work, but I can't get them to work at the same time. My code is in short like this (I'm not copying all code, just explaining it, so not all functions that I mention are real functions as you will see ^^):

button onclick="function() // Checks if tooltip exists and if yes, removes it. If not, creates it.
(works, no need to show you the code I think).





$(window).click(function()
{
 if(tooltip exists)
  if(clicked outside the tooltip)
   remove tooltip
});

Now the problem is (I think) that when the button is clicked the onclick="" is executed BEFORE the window.click function is executed, as the tooltip appears to exist (and is removed!) when the window.click function checks for its presence as soon as I click the button. When I change the window.click function to window.mouseup, the tooltip does not get removed when I click the button, but it does when I click outside the element, which is great. Only problem is that the tooltip now does not get removed anymore when I click the button again.. Help please!

Edited by minitauros

2
Contributors
4
Replies
7
Views
4 Years
Discussion Span
Last Post by minitauros
0

You can make a simple test to verify what occurs.

Declare a var buttonClicked = false. Inside the $(button).click() set it as true, then inside the $(window).click() alert the var to see it's state.

If the button is 'clicked' before, you can use this var to ignore the event at the first window.click().

0

Yea I tried that, and somehow it is set to "true", that's why I figured the button's onclick event is handled before the window.click event :). Thanks for your input though! Any other clues on how I could get this to work?

2

So, if you have the var setted to true, you can ignore the window.click. And after ignoring the window.click, set the var to false, so that in the next click you can close it.

Doesn't that work? Any doubts in this implementation?

0

Sorry for the late response, was on a trip to Dublin :). Thanks for the reply, that does sound like a solution. Can't remember 100% accurately what the problem was at the current moment (as I've been away for a couple of days) but I'll surely check it out!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.