I have a set of tabs and want to add mouseover functionality to them. I don’t want this functionality to be applied to .active.
Markup:
<ul>
<div class='tab'>my tab</div>
<div class='tab' data-id='1'>your tab</div>
</ul>
<script>
$('.tab').on('click',function(){
$(this).addClass('active');
});
</script>
I have tried this:
$('.tab').not('.active').on('mouseover', function(){
and
$('.tab:not(.active)').on('mouseover', function(){
But neither of these work. How would I exclude that active from this functionality?
That is the issue. When adding the
mouseoverevent on load, the active class isn’t present, so the.not()doesn’t exclude anything. Instead you need to check for the class inside the handler itself.Try this:
Example fiddle