Reputation: 4740
I am attempting to produce a simple image gallery.
Currently I have one large class with a background image containing a full size version of one of the lower 5 thumbnails. When I click on one of the 5 thumbnails I want the background image of the large class to change to a larger version of the thumbnail that was just clicked.
I have attempted to use the toggleClass()
method to change the class to one with a background image that matches the thumbnail image but currently it isn't working.
I set up a JSfiddle to demonstrate with the first two thumbnails, currently changing the class should only change the background color to simplify it a bit.
So why isn't the class being changed when the second image with id thumb2
is clicked?
Thanks
Upvotes: 0
Views: 110
Reputation: 17366
use
$(".main-image1").toggleClass("main-image2");
Don't use .
at the toggleClass()
Upvotes: 1
Reputation: 123739
Sytnax issue:-
Change this
$(".main-image1").toggleClass(".main-image2");
to
$(".main-image1").toggleClass("main-image2");
When providing a class selector you need to provide .
but in the add/remove/toggleClass operation it should be the name of the class alone.
Upvotes: 2
Reputation: 8301
Remove the dot in main-image2
$(".main-image1").toggleClass("main-image2");
Upvotes: 3