April 9, 2012

html mouse over event, can't show dialog

Question by user595234

I want to show a tooltip based on mouse over event . I have tried this code, but failed, nothing will show up.

Please advise.

<img onmouseover="showLongText();" BORDER=0 height=15 width=15 src="images/pick-button.gif"/>
<div id="longTextDiv" style="display:none;">
ddd
</div>

<script type="text/javascript">
function showLongText(className, fldName, objId){   
    var longTextDiv = $("#longTextDiv");
    //alert(longTextDiv);
    longTextDiv.style.leftPos += 10;
    longTextDiv.style.posLeft = event.clientX;
    longTextDiv.style.posTop = event.clientY;
    longTextDiv.style.display = "";
    longTextDiv.setCapture();           
}
</script>

Answer by Starx

Since you are already using jQuery. You should use

$("img").hover(function(e) {
    var longTextDiv = $("#longTextDiv");
    //alert(longTextDiv);
    longTextDiv.css({
       left : e.pageX,
       top : e.pageY, 
       display : "block"
    });
    longTextDiv.setCapture();           
});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!