How Take An Element That Appear When I Click A Button October 26, 2023 Post a Comment Suppose to have an html page and when I click on one button I read:' I need to handle when I click 'ok' that is html code: Solution 1: This piece of Jquery code should work:$('button[data-bb-handler="confirm"][type="button"]').click(function(){ console.log("MAREEEEEEEEEEEEEEEEE "+$(this).length); }); CopyLet me know if it did not work. Check this Working CodepenSolution 2: I am suggesting to use Bootbox JS. it is based on Bootstrap layout.You can achieve that you need as mentioned belowbootbox.confirm("Are you sure?", function(result) { // write your code what you need to handle on OK button }); CopySolution 3: You may use the event show.bs.modal://// On modal show// $(document).on('show.bs.modal', function (e) { //// attach the click event for OK button// $('button[data-bb-handler="cancel"][type="button"]').on('click', function (e) { console.log("CANCEL BUTTON PRESSED"); }); //// attach the click event for CANCEL button// $('button[data-bb-handler="confirm"][type="button"]').on('click', function (e) { console.log("OK BUTTON PRESSED"); }); }); $(document).ready(function() { $('#myBtn').on('click', function (e) { bootbox.confirm("Are you sure you wish to discard this post?", function () { }); }).trigger('click'); });Copy<linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"><scriptsrc="https://code.jquery.com/jquery-2.1.1.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script><scriptsrc="https://github.com/makeusabrew/bootbox/releases/download/v4.4.0/bootbox.min.js"></script><buttonid="myBtn"type="button"class="btn btn-primary">Click Me</button>CopyThis is the bootbox.confirm message. For deatils you may refer to Bootbox.js.When you click on the ok or cancel the dialog dom element is removed from the document.So you have to use the callback function:$(document).on('click.bootbox', function(e, result){ console.log("Pressed "+ result); }); bootbox.confirm("Are you sure you wish to discard this post?", function(result) { $(document).trigger('click.bootbox', result); });Copy<linkhref="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"><scriptsrc="https://code.jquery.com/jquery-2.1.1.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script><scriptsrc="https://github.com/makeusabrew/bootbox/releases/download/v4.4.0/bootbox.min.js"></script>Copy Share Post a Comment for "How Take An Element That Appear When I Click A Button"
Post a Comment for "How Take An Element That Appear When I Click A Button"