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..?
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.
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.
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.
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; }
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With