Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8726259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:12:41+00:00 2026-06-13T08:12:41+00:00

I am trying to create a small 20x20px div box, that when clicked opens

  • 0

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.

  1. #container clicked and #box fadeIn();
  2. Item in #box is clicked
  3. #box fadeOut()

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:

  1. Click #container
  2. #box fades in
  3. Click #box img
  4. // Do things, removed for example
  5. #box fades out
  6. #box fades 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

http://jsfiddle.net/8FuBD/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:12:42+00:00Added an answer on June 13, 2026 at 8:12 am

    You need to use event.stopPropagation(). The event is bubbling up which is causing the div to fade in again.

    $(document).on("click", "#box img", function(e){
        e.stopPropagation();
        // Do things, removed for example
    
        $("#box").fadeOut();        
    });​
    

    http://jsfiddle.net/ycpFL/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a small html fragment (a div element) consisted of three
I am trying to create a small indicator inside of a UIButton . Ive
I am trying to create a small web app that will allow users to
I have a small program that I'm trying to create to get ip addresses
I'm trying to create a small web app that is used to remove items
Trying to create a box that contains sentences (with spaces) and can have a
I am trying create a small web application that allows a user to login
having a small problem. I'm trying to create a loop that will create an
I'm trying to create a small application that interacts with the Product API of
I am trying to create a small function that returns the number of spaces

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.