Reputation: 1862
I have some effects in my menu, which works fine, but these effects shouldn't trigger on a menupoint which belongs to class "active". How should I do that? Using eval or similar things?
To sum it up: I want to deny an effect if the trigger has a special class.
Upvotes: 0
Views: 1187
Reputation: 101543
In each of your mouse events, use .hasClass()
in an if()
statement:
$('.selector').mouseout(function() {
if($(this).hasClass('active'))
{
return;
}
// The rest of your code.
});
Here, the if()
checks to see whether the element the event was fired on has the class active
. If it does, the function return
s, not executing any more code inside it.
You haven't given any code or HTML to work with, so this is a general solution. Please update your question with more detail so I can give you a better answer.
Upvotes: 2
Reputation: 7330
bind to (not) active
like this:
$('.menuitem:not(.active)').live('mouseout',function(){});
Upvotes: 1
Reputation: 2376
JamWaffles and Cito's way works and are the most effective but just as an alternative you could also do it like this, first fetch the class value:
var className = $('.myclass').attr('class');
Then you want to check the value
if (className != 'whatever') {
// animate and stuff etc
}
But like I said, the other methods are better so you might as well use the built in features of jQuery such as hasClass
- just showing theres more than one way to tackle problems :)
Upvotes: 1
Reputation: 5613
In the trigger function, just wrap your code with
if ($(this).not('.active')) {
...
}
Upvotes: 1