I have an image gallery.
When I click on it, the images stand out because the body background goes from white to black.
When I click again on the image it goes back to normal.
This is what I have for now :
$('img').click(function () {
$('body').toggleClass("darken");
});
I’d like my users to be able to click anywhere on the page and remove the class “darken”.
I tried the hasClass statement but with no success.
if ($('body').hasClass('darken')) {
$('body').click(function () {
$(this).toggleClass("darken");
});
}
Thank you very much,
Clément.
You can bind the click event handler to
<body>. But, be sure to stop the propagation of the click event onimg.