I think you're almost there.
The thing is, your $(this)
in the "close button" listener is not the clickable div. So you want to search it first. try to replace $(this)
with $(this).closest(".clickable")
. And don't forget the e.stopPropagation()
as Guilherme is suggesting. that should be something like:
$( document ).ready(function() {
$(document).on("click", ".close_button", function () {
alert ("oi");
e.stopPropagation()
$(this).closest(".clickable").addClass("spot");
$(this).closest(".clickable").removeClass("grown");
});
$(document).on("click", ".clickable", function () {
if ($(this).hasClass("spot")){
$(this).addClass("grown");
$(this).removeClass("spot");
}
});
});