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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:25:30+00:00 2026-05-24T16:25:30+00:00

I have a div that acts as a tooltip, and a link to show

  • 0

I have a div that acts as a tooltip, and a link to show this tooltip. This part works fine.

<div class="tooltip">
     <span class="tooltip_help">
        <a onclick="toggleTooltips('tooltip1');" title="Tip">
            <img src="/ca/images/general/tooltip.png" alt="tooltip icon" title="Tip" align="absmiddle" border="0" />
        </a>
    </span> 
    <div id="tooltip1" class="tooltip_box">
        <span>
           tip text here.
        </span>
    </div>
</div> 

What I’m trying to do is set is so that it will hide with a click anywhere on the page (including inside of the div itself). I’m pretty close to having it, but it sometimes requires double clicks, and sometimes will show itself based on a click anywhere on the page. This is with mootools.

<script language="javascript" type="text/javascript">
function toggleTooltips(id) {
    var e = document.id(id);
    if(e.style.display=='block') {
        e.style.display='none';
        document.removeEvent('click', function() {
            toggleTooltips(id);
        });
    } else {
        e.style.display='block';
        document.addEvent('click', function() {
            toggleTooltips(id);
        });
    }
}
</script>

Any help would be appreciated.

  • 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-24T16:25:31+00:00Added an answer on May 24, 2026 at 4:25 pm

    I’m no mootools expert, but I’d imagine that you need to call addEvent and removeEvent with the exact same function – not two functions that do the same thing. My guess is that mootools can’t remove the click-listener because it’s looking for a function that hasn’t actually been registered. I.e. it’s looking for function A, but the function you registered is function B. They do the same thing, but they aren’t the same function.

    The result is that the click-listener on the document is never removed, and instead toggles the element with every click – and a new toggle-function is added each time too. Once you’ve clicked a few times, clicking anywhere in the document results in the element toggling back and forth X number of times. If X is an odd number, it seems to work as expected. If it’s even, it won’t have any apparent effect.

    Try this

    function toggleTooltip(id) {
        var e = document.id(id);
        if( !e.toggleCallback ) {
            e.toggleCallback = function() { toggleTooltip(id); };
        }
        if(e.style.display=='block') {
            e.style.display='none';
            document.removeEvent('click', e.toggleCallback);
        } else {
            e.style.display='block';
            document.addEvent('click', e.toggleCallback);
        }
    }
    

    I’d also advise you to not use the onclick attribute, since you’re already using mootools. Instead, set up an event listener to fire when the document has loaded. Then use that to find the elements that need toggling, and set everything up there.

    Edit: Here’s what I mean: http://jsfiddle.net/au32j/1/

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

Sidebar

Related Questions

I have a list like this: <ul> <li id=adm-thumb onclick=javascript:addBanner('bowling.jpg');> <div class=adm-tick></div> <img src=img/banners/bowling.jpg
I have a div that's set to overflow: auto; . This contents of this
If I have a div that acts like a box, and I make it
I would just like to have an editable div that acts like a textarea
I have a div on my page that acts as a shell to store
i have a div on a web page that basically acts as a panel
I have a jquery-script that triggers on mouseover on a div like this: <div
I have a div that acts like a drop-down. So it pops-up when you
I have a div that has it's opacity set to 60. Inside the div,
I have a DIV that I want to touch the bottom of the screen

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.