I have a "help" area on my page and anytime the user hovers over a table the help information should be updated. The problem is within the table I have a check box in 1 cell of each row, and when the user hovers over that checkbox I want the mouseover event of the checkbox to override the table event and for the checkbox help to be displayed. Currently the table mouseover works fine but nothing happens when I mouse over the checkbox.
<table class="myTable">
<tr>
<th>Col1</th>
<th>Col2</th>
</tr>
<tr>
<td><input class="myCheckbox" type="checkbox" /></td>
<td>Cell 2</td>
</tr>
<tr>
<td><input class="myCheckbox" type="checkbox" /></td>
<td>Cell 3</td>
</tr>
</table>
<div class="myHelpMenu"></div>
$('.myCheckbox').mouseover(function() {
$('.myHelpMenu').html("this is my checkbox help");
});
$('.myTable').mouseover(function() {
$('.myHelpMenu').html("this is my tables help");
});
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 mouseover event is fired at an Element when a pointing device (such as a mouse or trackpad) is used to move the cursor onto the element or one of its child elements.
The mouseover event triggers when the mouse pointer enters the div element, and its child elements. The mouseenter event is only triggered when the mouse pointer enters the div element. The onmousemove event triggers every time the mouse pointer is moved over the div element.
mouseover: The onmouseover event triggers when the mouse pointer enters an element or any one of its child elements. mouseenter: The onmouseenter event is triggered only when the mouse pointer hits the element.
LIVE DEMO
This is a nice way to detect using mouseover
the current target
element that is hovered, than using pure JS to retrieve the .tagName
you can create a messages list object and retrieve the desired one.
$('.myTable').mouseover(function( e ) {
var tag = e.target.tagName;
var messages = {
"INPUT" : "this is my checkbox help",
"TABLE" : "this is my tables help"
};
$('.myHelpMenu').text( messages[tag] );
});
If you want to clear your info message do like:
$('.myTable').on('mouseover mouseleave',function( e ) {
var tag = e.target.tagName;
var messages = {
"INPUT" : "this is my checkbox help",
"TABLE" : "this is my tables help"
};
$('.myHelpMenu').text( messages[tag] );
if(e.type=='mouseleave')
$('.myHelpMenu').empty();
});
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