Thatoneguy7
Thatoneguy7

Reputation: 37

jquery class manipulation

Im getting an "unexpected ;" error at line 4 and I don't see it.

$('.socialtag').hover(function(){
var tab = $(this);
if(!tab.hasClass('extended')){
    $(tab.addClass('extended');
    $(tab).animate({
            left: '1115px'
    }, 1500)
}
else{
    $(tab).animate({
            left: '975px'
        },1500);
    $(tab.removeClass('extended')
    };
};

I've been staring at it for an hour now, and I really don't see it. It is supposed to take an image with the class .socialtag and check if it has the class extended. If not then it should change the css left property to 1115px in 1.5 seconds and add the extended class. If so then it changes the property to 975 (which the image already has by default so there would be no visual change).

Can anyone see my error?

Upvotes: 0

Views: 48

Answers (3)

Nejib
Nejib

Reputation: 11

$(tab.addClass('extended'); missing parenthesis,

Try this: $(tab).addClass('extended');

Upvotes: 0

Stphane
Stphane

Reputation: 3456

$(tab.addClass('extended');

missing parenthesis at least

$(tab.addClass('extended'));

Upvotes: 1

Dhaval Marthak
Dhaval Marthak

Reputation: 17366

Try using this:

tab.addClass('extended');
........................
tab.removeClass('extended');

As you are already initializing element object to variable so no need to use $ before $(...)

Or

You can do like this:

$(tab).addClass('extended');
$(tab).removeClass('extended');

Hope this helps!

Upvotes: 0

Related Questions