Jquery live confirm

I'm having problems with .live()and confirm. It multiplies confirmation dialogs with every click. I know about .die(), but I can't get it to work.

$("button.del").live("click", function(){

        if(!confirm("Are you sure?")) {
            //close
        }

    });

I tried $("button.del").die("click");right after the above code, and in this case confim doesn't even work.

+3
source share
3 answers

Thanks to everyone for your answers ... it turned out that it was a mistake in my code ... Sorry ...

I did not see this ... part of the confirmation code was reloaded every time I clicked ... hence, multiplication ...

+1
source

Does the dialog box appear several times if you just run this code yourself?

, , .live() . , .

, .

, , .

+1

HTML-.

, , .del , , . :

<div class="testclass">
    test
    <div class="testclass">
        test2
    </div>
</div>

...

$(".testclass").click(function() { alert("test"); });

, ,

$(".testclass").click(function() { alert("test"); });
$(".testclass").click(function() { alert("test"); });

. live - . click()?

+1

Source: https://habr.com/ru/post/1731155/


All Articles