JavaScript/jQuery on click, confirm fires twice JavaScript/jQuery on click, confirm fires twice google-chrome google-chrome

JavaScript/jQuery on click, confirm fires twice


I think you should use .one

$(document).one('click', '.myBtn', function () {

Description: .one() Attach a handler to an event for the elements. The handler is executed at most once per element per event type.


Try to clear your cache in chrome setting as well as history of the file And then close your browser.Then try again.

I use this code similar like you and it works!

<script>    //$(document).ready(function () {        $(document).on('click', '.myBtn', function () {            console.log('Let us check...');            var confirmation = confirm('Are you sure you want ' + $(this).data('field') + '?');            console.log(confirmation);        });   // });</script>

It fires one! That's chrome. I'm not sure it is a bug. It's perhaps the way chrome store it.But I haven't try in Opera at Mac (since, I have no mac with me)


matomo