Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  173] [ 2]  / answers: 1 / hits: 20033  / 12 Years ago, thu, march 7, 2013, 12:00:00

I can't use jQuery for this part of the project due to various reasons. SO I need to detect this in vanilla js. I tried this but it doesn't work:



http://jsfiddle.net/qHfJD/



var myDiv = document.getElementById('foo');

myDiv.onmouseenter = function() {
alert('entered');
}

myDiv.onmouseleave = function() {
alert('left');
}

More From » javascript

 Answers
5

mouseenter and mouseleave are proprietary MS events (that are actually pretty nice). If myDiv has no children, using mouseover / mouseout will have exactly the same effect.



http://jsfiddle.net/qHfJD/1/



Note: this original question and answer were very old and from a time when mouseenter and mouseleave were not well supported outside of IE. All modern browsers have supported these events on elements for quite some time now. They are generally preferred over mouseover/mouseout because the latter will trigger for each child of the element with the event listener in addition to the element itself.


[#79750] Thursday, March 7, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
siena

Total Points: 199
Total Questions: 91
Total Answers: 91

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;