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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:43:54+00:00 2026-06-06T12:43:54+00:00

I have a JS for tooltip on Mouseover, What should i change to convert

  • 0

I have a JS for tooltip on Mouseover,

What should i change to convert the mouseover to onclick event in this JS.

I tried replacing some but didnt work ! Here is the JS below. But it didnt work, Instead it was showing an error.

Can it be done or all the code needs to be changed !

var htmltooltip={
tipclass: 'htmltooltip',
fadeeffect: [true, 500],
anchors: [],
tooltips: [], //array to contain references to all tooltip DIVs on the page

positiontip:function($, tipindex, e){
    var anchor=this.anchors[tipindex]
    var tooltip=this.tooltips[tipindex]
    var scrollLeft=window.pageXOffset? window.pageXOffset : this.iebody.scrollLeft
    var scrollTop=window.pageYOffset? window.pageYOffset : this.iebody.scrollTop
    var docwidth=(window.innerWidth)? window.innerWidth-15 : htmltooltip.iebody.clientWidth-15
    var docheight=(window.innerHeight)? window.innerHeight-18 : htmltooltip.iebody.clientHeight-15
    var tipx=anchor.dimensions.offsetx
    var tipy=anchor.dimensions.offsety+anchor.dimensions.h
    tipx=(tipx+tooltip.dimensions.w-scrollLeft>docwidth)? tipx-tooltip.dimensions.w : tipx //account for right edge
    tipy=(tipy+tooltip.dimensions.h-scrollTop>docheight)? tipy-tooltip.dimensions.h-anchor.dimensions.h : tipy //account for bottom edge
    $(tooltip).css({left: tipx, top: tipy})
},

showtip:function($, tipindex, e){
    var tooltip=this.tooltips[tipindex]
    if (this.fadeeffect[0])
        $(tooltip).hide().fadeIn(this.fadeeffect[1])
    else
        $(tooltip).show()
},

hidetip:function($, tipindex, e){
    var tooltip=this.tooltips[tipindex]
    if (this.fadeeffect[0])
        $(tooltip).fadeOut(this.fadeeffect[1])
    else
        $(tooltip).hide()   
},

updateanchordimensions:function($){
    var $anchors=$('*[@rel="'+htmltooltip.tipclass+'"]')
    $anchors.each(function(index){
        this.dimensions={w:this.offsetWidth, h:this.offsetHeight, offsetx:$(this).offset().left, offsety:$(this).offset().top}
    })
},

render:function(){
    jQuery(document).ready(function($){
        htmltooltip.iebody=(document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
        var $anchors=$('*[@rel="'+htmltooltip.tipclass+'"]')
        var $tooltips=$('div[@class="'+htmltooltip.tipclass+'"]')
        $anchors.each(function(index){ //find all links with "title=htmltooltip" declaration
            this.dimensions={w:this.offsetWidth, h:this.offsetHeight, offsetx:$(this).offset().left, offsety:$(this).offset().top} //store anchor dimensions
            this.tippos=index+' pos' //store index of corresponding tooltip
            var tooltip=$tooltips.eq(index).get(0) //ref corresponding tooltip
            if (tooltip==null) //if no corresponding tooltip found
                return //exist
            tooltip.dimensions={w:tooltip.offsetWidth, h:tooltip.offsetHeight}
            $(tooltip).remove().appendTo('body') //add tooltip to end of BODY for easier positioning
            htmltooltip.tooltips.push(tooltip) //store reference to each tooltip
            htmltooltip.anchors.push(this) //store reference to each anchor
            var $anchor=$(this)
            $anchor.hover(
                function(e){ //onMouseover element
                    htmltooltip.positiontip($, parseInt(this.tippos), e)
                    htmltooltip.showtip($, parseInt(this.tippos), e)
                },
                function(e){ //onMouseout element
                    htmltooltip.hidetip($, parseInt(this.tippos), e)
                }
            )
            $(window).bind("resize", function(){htmltooltip.updateanchordimensions($)})
        })
    })
}
}

htmltooltip.render()
  • 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-06T12:43:56+00:00Added an answer on June 6, 2026 at 12:43 pm

    As I see (have not tried it) you just have to replace

    $anchor.hover( 
                function(e){ //onMouseover element 
                    htmltooltip.positiontip($, parseInt(this.tippos), e) 
                    htmltooltip.showtip($, parseInt(this.tippos), e) 
                }, 
                function(e){ //onMouseout element 
                    htmltooltip.hidetip($, parseInt(this.tippos), e) 
                } 
            )
    

    with

    $anchor.click( 
                function(e){ //onMouseover element 
                    htmltooltip.positiontip($, parseInt(this.tippos), e) 
                    htmltooltip.showtip($, parseInt(this.tippos), e) 
                }
            ) 
    

    but you will have to add a “close” button to the tooltip to hide it again. Or any other solution/behavior you would like to have.

    update:

    You could try to set the “onclick” handler of the tooltip.
    Could look like:

    showtip:function($, tipindex, e){   
        var tooltip=this.tooltips[tipindex]   
        if (this.fadeeffect[0])   
            $(tooltip).hide().fadeIn(this.fadeeffect[1])   
        else   
            $(tooltip).show()  
    
        $(tooltip).bind('click', 
            function(e) 
            {
                htmltooltip.hidetip($, tipindex, e);
            }
        ); 
    },
    
    hidetip:function($, tipindex, e){             
        var tooltip=this.tooltips[tipindex]             
        if (this.fadeeffect[0])             
            $(tooltip).fadeOut(this.fadeeffect[1])             
        else             
            $(tooltip).hide()  
    
        $(tooltip).unbind('click');              
    },             
    

    But its just an idea… and the user would have to click the tooltip not the button…

    An other one would be to have ids at your tooltips and the same id at the close buttons with a prefix or so (for example “tooltip1_closeButton”).
    Than you could attach the onclick event of the buttons in the “render” function like

    $(tooltip.id + "_closeButton").bind("click", 
        function(e)
        {
            htmltooltip.hidetip($, parseInt(this.tippos), e) 
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This sounds like it should be easy but for some reason it's not work
I have a problem using a onclick event on a xp:link and a mouseover
I want to show a tooltip based on mouse over event . I have
I have tooltip(prototip, but it doesnt matter) on my page in javascript and I
I have some toy code for a tooltip. It works okay, except that when
I have this code below which works fine but seems unnecessary as it loops
I have a check box that is disabled that should be showing a tooltip
I am trying to show a tooltip in a mouseover event. The reason I
I have this function where I need to show tooltip when the mouse is
I have a View in which I'm using a tooltip provided by this site:

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.