I am trying to create a small 20x20px div box, that when clicked opens a 200x200px box located inside the first box:
HTML
<div id="container" style="width:20px; height:20px;">
<div id="box" style="display:none;width:200px; height:200px;">
<img src="example1.gif" />
<img src="example2.gif" />
</div>
</div>
Aim
My aim is to make it so when #container is clicked, #box is faded in. The user will then click an image inside this box and the #box will then fade out.
#containerclicked and#boxfadeIn();- Item in
#boxis clicked #boxfadeOut()
To do this I am using the following jQuery:
$(document).on("click", "#container", function(){
$("#box").fadeIn("fast");
});
$(document).on("mouseleave", "#box", function(){
$("#box").fadeOut("fast");
});
$(document).on("click", "#box img", function(){
// Do things, removed for example
$("#box").fadeOut();
});
What actually happens
At the moment it's not working though because this happens:
- Click
#container #boxfades in- Click
#box img - // Do things, removed for example
#boxfades out#boxfades in
Number 6. on the above list should not happen, the box should not fade back in.
I think the problem is with .on("click", "#container", function(){ this may be applying that code when #container #box img is clicked, how can I stop this?
Demo