JSFiddle - React, Tailwind, and code Playground
HTML
<button data-confirm-text="You sure you want to submit?">Submit with Custom Prompt</button>
JavaScript
(function( $ ) {
$.fn.confirmAction = function() {
return this.each( function() {
var $this = $( this ),
confirmText = $this.data( "confirmText" );
$this.bind( "click.confirmAction", function( e ) {
if ( confirmText ) {
if ( confirm( confirmText ) ) {
console.log( "Confirmed" );
} else {
console.log( "Denied" );
e.preventDefault();
e.stopImmediatePropagation();
}
}
});
});
};
})( jQuery );
$( document ).on( "click", "button", function() {
alert( "Submit Form: Live" );
});
$( "button" ).confirmAction();
$( "button:first" )
.unbind( ".confirmAction" )
.data( "confirmText", "Are you really really sure you want to submit?" )
.confirmAction();
$( "button" ).on( "click", function() {
alert( "Submit Form: Bind" );
});