2

JS function:

function DisplayToolTip() {
    document.getElementById('divToolTip').style.left = window.event.x;
    document.getElementById('divToolTip').style.top = window.event.y;
    document.getElementById('divToolTip').style.visibility = 'visible';
}

function HideToolTip() {
    document.getElementById('divToolTip').style.visibility = 'hidden';
}

HTML:

<span id="spanName" style="font-weight: bold;border: solid 2px red;" onmouseover="javascript:DisplayToolTip();" onmouseout="javascript:HideToolTip();">
    THIS IS THE SPAN
</span>

<div id="divToolTip" style="position: absolute; visibility: hidden; z-index: 20; background-color: white; border: solid 1px Blue;">
    This is ToolTip Text
</div>

With this I got a JS error that is window.event.x is not defined. Can anyone help me solve this problem?

2
  • 1
    If you're not doing this as a learning exercise, I'd suggest using qTip2, as it saves re-inventing the wheel. Commented Jan 28, 2013 at 10:00
  • It is not defined cause in your DisplayToolTip function you use event var, which should be passed to it as a function parameter. Commented Jan 28, 2013 at 10:01

1 Answer 1

1

You should use jQuery in this method

jQuery(".abc").mousedown(function(e){ 
        jQuery('#divToolTip').css('top',(e.pageY)+'px');
        jQuery('#divToolTip').css('left',(e.pageX)+'px');
        jQuery('#divToolTip').css('visibility', 'visible');
}); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.