Search code examples
javascriptjquerybootstrap-4bootstrap-confirmation

How to disable bootstrap confirmation click listener?


I am using javascript to enable confirmation (http://bootstrap-confirmation.js.org/) as below:

$ (className).confirmation ({...})

when I click the dom with the given className it will trigger the confirmation dialog. I wonder how I can remove this click event through javascript?


Solution

  • All you have to do is use a built-in method from bootstrap confirmation

    $('#element').confirmation('hide');
    

    Snippet

    $('[data-toggle=confirmation]').confirmation('hide');
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap-confirmation2/dist/bootstrap-confirmation.min.js"></script>
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <button class="btn btn-default" data-toggle="confirmation">Confirmation</button>