Reputation: 549
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
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 .
Upvotes: 3
Reputation: 8168
You have to use this
$(this).toggleClass("floatRightImage1");
You can get more info about this
here
Upvotes: 1
Reputation: 31749
Remove the .
and use $(this)
as it will refer to the current object. -
$(this).toggleClass("floatRightImage1");
Syntax
.toggleClass( className )
Upvotes: 1