Event does not work after executing replaceWith

1

I use this plugin: link

Follow JSFiddle: link

After clicking on the "replaceWith" button, the "Confirmation" button will no longer work.

Follow the code below:

$('#teste').confirmation();

$("#replaceWith").click(function() {
  $('#teste').replaceWith('<button id="teste">Confirmação</button>');
});

The "Confirmation" button does not work after clicking the "replaceWith" button.

Update @RicardoPontual :

Follow the code below:

$('[data-toggle=confirmation-document]').confirmation({
    singleton: true,
    popout: true,
    rootSelector: '[data-toggle=confirmation-document]',
    title: '',
    content: '',
    buttons: [
        {
            label: 'Criar',
            onClick: function () {
                //códigos
            }
        },
        {
            label: 'Apagar',
            onClick: function () {
                //códigos
            }
        }
    ]
});

Any solution?

    
asked by anonymous 30.07.2018 / 17:36

2 answers

4

Yes, you replaced the content and lost the event, simply add the event again:

var ops = { ... };
$( "#replaceWith" ).click(function() {
   $('#teste').replaceWith('<button id="teste">Confirmação</button>');
   $('#teste').confirmation(ops);
});

Here's the updated fiddle: link

    
30.07.2018 / 18:06
2

The code is a bit confusing on your Fiddle, but what I could tell is that replace "kills" the entire configuration made for button id="teste"

I made a small change:

$( "#replaceWith" ).click(function() {
$('#teste').replaceWith('<button id="teste">Confirmação</button>');
$('#teste').confirmation();
});
$('#teste').confirmation();

and it works, see: link

I have not debugged JQuery to know what is done in terms of event association after replaceWith , but I think it's related to that: Events not registering after replaceWith

    
30.07.2018 / 17:57