Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .hasClass method to omit effect

Tags:

jquery

class

I've created a simple background effect for some tabs on a page but don't want that effect to fire if the tab has the class 'current'.

I presume there is a way to do this using .hasClass

Here's what I'm using for the effect:

$('ul.htabs a').mouseover(function(){

 $(this).stop().animate(
  {backgroundPosition:"(0 -810px)"}, 
  {duration:150},
  {easing: 'easeOutCubic'})
 }).mouseout(function(){
 $(this).stop().animate(
  {backgroundPosition:"(0 -806px)"}, 
  {duration:150},
  {easing: 'easeInCubic'})
 });
like image 862
Mr Jonny Wood Avatar asked Dec 04 '25 19:12

Mr Jonny Wood


2 Answers

You could also put it in the selector:

$('ul.htabs:not(.current) a').mouseover(function(){ ... });
like image 90
garann Avatar answered Dec 06 '25 12:12

garann


.mouseover(function(e) {

if ( $(this).hasClass('lol') ) {
  return;
}

if the element has a class of lol kill the function by returning immediately.

like image 40
meder omuraliev Avatar answered Dec 06 '25 11:12

meder omuraliev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!