I\'m trying to do something very simple. Basically I have a clickable div \'hot spot\', when you click that it fills the screen and displays some content. I achieved this by
Whenever I see addClass
and removeClass
I think why not just use toggleClass
. In this case we can remove the .clickable
class to avoid event bubbling, and to avoid the event from being fired on everything we click inside of the .clickable
div
.
$(document).on("click", ".close_button", function () {
$(this).closest(".grown").toggleClass("spot grown clickable");
});
$(document).on("click", ".clickable", function () {
$(this).toggleClass("spot grown clickable");
});
I also recommend a parent wrapper for your .clickable
divs
instead of using the document
. I am not sure how you are adding them dynamically so didn't want to assume your layout for you.
http://jsfiddle.net/bplumb/ECQg5/2/
Happy Coding :)