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 6986915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:52:10+00:00 2026-05-27T18:52:10+00:00

I have some jquery code inserting a div like this function popUpBox(){ $(.openBox).click(function(){ var

  • 0

I have some jquery code inserting a div like this

function popUpBox(){
$(".openBox").click(function(){     
    var id = $(this).attr('id');
    $("#"+id).append('<div class="box1"><div class="button1">Submit</div></div>');
    closeBox();
});
}

function closeBox(){
     $(".button1").click(function(){
          $(".box1").remove();
     });
}

The function popUpBox is called on document.ready. And of course I have a div like this…

<div class="openBox" id="id1">Open Box</div>

The closeBox() function does not seem bind the remove() event to the button. I have tried to use a bind and parent.remove but to no avail.

  • 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-05-27T18:52:11+00:00Added an answer on May 27, 2026 at 6:52 pm

    Your code works. The problem is that the click on the Submit buttons also triggers the parent event handler. So you are removing the popup box, but immediately adding one again.

    Prevent triggering the parent event handler by stopping the event from bubbling up:

    function closeBox(){
         $(".button1").click(function(e){
              e.stopPropagation();
              $(".box1").remove();
         });
    }
    

    quirksmode.org has a great article about this.

    DEMO

    That said, instead of binding the event handler every time again, you can bind it once and use event delegation:

    function popUpBox(){
        $(".openBox").click(function(){     
            $(this).append('<div class="box1"><div class="button1">Submit</div></div>');
    
        }).on('click', '.button1', function(e) {
            e.stopImmediatePropagation();
            $(this).closest('.box1').remove();
        });
    }
    

    DEMO

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

Sidebar

Related Questions

I have some jQuery code something like this: $(document).ready(function() { $(img.off).click(function() { alert('on'); $(this).attr('class',
I have some jQuery code like this: // Called right away after someone clicks
I have written some simple jquery code : function Generate(result, counter) { $(#ArchivesContent).append( <table
I have some JQuery Code as follows: $(#sh-zone-button-cart-menu).live(click, function(event) { event.preventDefault(); $(#sh-zone-cart-menu).toggle(0, function(){ if($(this).is(:visible)){
I have some pretty basic jQuery code: ... $(this).find('img').load(function(){ loadedImages++; if(loadedImages == $this.find('img').length){ ...
I have some jQuery code. I have called an Ajax function file, file.php, that
I have some jQuery code that intercepts links clicked on a page: $(document).ready(function() {
I have some jquery code the creates an quantity text box. Like so <input
I have some JQuery code that shows or hides a div. $(div#extraControls).show(); // OR
I have some jQuery code that I would like reviews and pointers on on

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.