Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Description Box using "onmouseover"

I am playing with the onmouseover event in javascript

I would like a little box to pop up and remain up until there is no onmouseover anymore

I think it's called a description box, but I am not sure.

How do I get a little box to pop up with custom text when I put my mouse over certain text, and disappear once I move the mouse to a different object..?

like image 237
Alex Gordon Avatar asked Aug 24 '10 17:08

Alex Gordon


People also ask

What is the use of onmouseover?

Definition and Usage The onmouseover event occurs when the mouse pointer is moved onto an element, or onto one of its children. Tip: This event is often used together with the onmouseout event, which occurs when a user moves the mouse pointer out of an element.

How do I use onmouseover and Onmouseout in HTML?

The onmouseout event occurs when the mouse pointer is moved out of an element, or out of one of its children. Tip: This event is often used together with the onmouseover event, which occurs when the pointer is moved onto an element, or onto one of its children.

What is hover in JavaScript?

Definition and Usage. The hover() method specifies two functions to run when the mouse pointer hovers over the selected elements. This method triggers both the mouseenter and mouseleave events. Note: If only one function is specified, it will be run for both the mouseenter and mouseleave events.


2 Answers

Assuming popup is the ID of your "description box":

HTML

<div id="parent"> <!-- This is the main container, to mouse over --> <div id="popup" style="display: none">description text here</div> </div> 

JavaScript

var e = document.getElementById('parent'); e.onmouseover = function() {   document.getElementById('popup').style.display = 'block'; } e.onmouseout = function() {   document.getElementById('popup').style.display = 'none'; } 

Alternatively you can get rid of JavaScript entirely and do it just with CSS:

CSS

#parent #popup {   display: none; }  #parent:hover #popup {   display: block; } 
like image 154
casablanca Avatar answered Sep 29 '22 17:09

casablanca


Although not necessarily a JavaScript solution, there is also a "title" global tag attribute that may be helpful.

<a href="https://stackoverflow.com/questions/3559467/description-box-on-mouseover" title="This is a title.">Mouseover me</a> 

Mouseover me

like image 23
Ohmless Avatar answered Sep 29 '22 17:09

Ohmless