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

  • Home
  • SEARCH
  • 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 6896709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:04:41+00:00 2026-05-27T07:04:41+00:00

<div> <ul> <li><a data-id=1 href=#>Show dialog 1</a></li> <li><a data-id=2 href=#>Show dialog 2</a></li> <li><a data-id=3

  • 0
<div>
  <ul>
    <li><a data-id="1" href="#">Show dialog 1</a></li>
    <li><a data-id="2" href="#">Show dialog 2</a></li>
    <li><a data-id="3" href="#">Show dialog 3</a></li>
    <li><a data-id="4" href="#">Show dialog 4</a></li>
    <li><a data-id="5" href="#">Show dialog 5</a></li>
    <li><a data-id="6" href="#">Show dialog 6</a></li>
  </ul>
</div>

<div class="dialogTest" style="display: none">
<p>Are you shure you want to delete this link?</p>
<p style="margin-top: 15px; text-align: center;"><button>Delete it!</button></p>
</div>
<div class="dialogTestMenu" style="display: none">
<p style="margin-top: 15px; text-align: center;"><a href="#">Delete this link</a></p>
</div>
$(function () {
    var ulMenu = function (target) {

    console.log('target item',target);

    $('.dialogTestMenu').dialog({
        title: 'Item #' + target.dataset.id + ' menu',
        modal: true,
        open: function () {
            var rootDialog = this;

            $(this).find('a').on('click', function () {
                $(rootDialog).dialog('close');

                $('.dialogTest').dialog({
                    title: 'Confirm delete #' + target.dataset.id,
                    modal: true,
                    open: function () {
                        var selfDialog = this;
                        $(this).find('button').on('click', function () {
                            console.log('target item to delete',target);
                            $(target).remove();
                            $(selfDialog).dialog('close');
                            return false;
                        });
                    },
                    buttons: {
                        Cancel: function () {
                            $(this).dialog('close');
                            $(rootDialog).dialog('open');
                        }
                    }
                });
                return false;
            });
        },
        buttons: {
            Cancel: function () {
                $(this).dialog('close');
            }
        }
    });

    };

    $('ul a').on('click', function () {
        ulMenu(this);
        return false;
    });
});

I have a list of items. Click on item calls dialog with menu . By clicking on menu item Delete this link I get another dialog with confirmation. When I cancel from the second dialog to delete first item (for example), and then I try to delete any other item, it deletes the first, which was cancelled.

Explain me, why do I get an old instance of target, when I try to handle click on button inside the second dialog.

Check out code, fill free to use console.

  • 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-27T07:04:41+00:00Added an answer on May 27, 2026 at 7:04 am

    Because you use .on() everytime a dialog opens it attach a new click function to buttons. I change your jsFiddle. Check it out. I unbind latest function and then bind new one, btw changed your construction a little bit.

    $(function () {
        var ulMenu = function () {
            var $this = $(this);
            $this.addClass('active');
    
            console.log('target item', this);
    
            $('.dialogTestMenu').dialog({
                title: 'Item #' + $this.data('id') + ' menu',
                modal: true,
                buttons: {
                    Cancel: function () {
                        $(this).dialog('close');
                        $('.wrap a.active').removeClass('active');
                    }
                }
            });
    
        };
    
        $('.dialogTestMenu a').bind('click', function () {
            $('.dialogTestMenu').dialog('close');
    
            var $current = $('.wrap a.active');
    
            $('.dialogTest').dialog({
                title: 'Confirm delete #' + $current.data('id'),
                modal: true,
                open: function () {
                    var selfDialog = this;
                    $(this).find('button').unbind('click').bind('click', function () {
                        console.log('target item to delete', $current.get(0));
                        $current.remove();
                        $(selfDialog).dialog('close');
                    });
                },
                buttons: {
                    Cancel: function () {
                        $(this).dialog('close');
                        $('.dialogTestMenu').dialog('open');
                    }
                }
            });
        });
    
        $('ul a').on('click', ulMenu);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What if I had somthing like this <div class=fb-like-box data-href= data-width=292 data-show-faces=true data-stream=true data-header=false
I have set a background on the data-role=page element like so <div data-role=page style=background:
I have a dialog - <div data-role=dialog id=msg-popup> <div data-role=header> <h1>Notification</h1> </div> <div data-role=content
This is my code <div data-role=page id=callAjaxPage> <img id=logo src=images/logo.JPG alt=logo /> <div data-role=header>
Say I have a select box eg <div data-bind='visible: someProp'> <select class=selectSubWidgets data-bind='options: subWidgets,optionsText:
I have a jquery dialog as follows - <div data-role=dialog id=msg-popup> <div data-role=header> <h1>Notification</h1>
I have the following HTML on a Jquery Mobile Page: <div data-role=controlgroup data-type=horizontal class=panelSwitcher>
atm I have something like this: $('#fish').append(<div data-bind='foreach: rows'> + <div ... + <p>...</p>..);
I have an UITableView and I want to populate it with data from this
HTML: <ul class=nav nav-tabs> <li><a href=#home data-toggle=tab>Home</a></li> <li><a href=#profile data-toggle=tab>Profile</a></li> <li><a href=#messages data-toggle=tab>Messages</a></li> <li><a

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.