jQuery class adding and removing with click and mouseleave
Posted
by danixd
on Stack Overflow
See other posts from Stack Overflow
or by danixd
Published on 2010-04-29T20:40:07Z
Indexed on
2010/04/29
20:47 UTC
Read the original article
Hit count: 282
jQuery
I just want to control a div by toggling a class on click, as well as removing it when the mouse leaves the div.
I had it working with mouseout, but when I entered over a child element, the mouseOut triggered, so I know I need to use mouseleave. I am just unsure how incorporate telling jQuery the mouse has entered.
Yes I am new to this! Here is my code:
$(function(){
$('.main').click(function() {
$(this).toggleClass('activated');
});
});
$(function(){
$('.main').mouseleave(function() {
$(this).removeClass('activated');
});
});
© Stack Overflow or respective owner