Stephen Kennedy
Stephen Kennedy

Reputation: 549

Jquery .toggleClass() issue

My simple jQuery toggleClass isn't working. Any help appreciated.

$(document).ready(function() {
    $(".floatRightImage").click(function() {
        $(".floatRightImage").toggleClass(".floatRightImage1");
    });
});

This is a very simplified version of it, I've created a fiddle of the simplified version which also isn't working here Fiddle

Upvotes: 0

Views: 78

Answers (3)

Satpal
Satpal

Reputation: 133453

You should pass the classname only to toggle it(without .). Also you should use it the current element context so use this

$(this).toggleClass("floatRightImage1"); //Note removed .

DEMO

Upvotes: 3

Abhinav
Abhinav

Reputation: 8168

You have to use this

$(this).toggleClass("floatRightImage1");

You can get more info about this here

Upvotes: 1

Sougata Bose
Sougata Bose

Reputation: 31749

Remove the . and use $(this) as it will refer to the current object. -

$(this).toggleClass("floatRightImage1");

Syntax

.toggleClass( className )

Docs

Upvotes: 1

Related Questions