javascript-confirm 1.0
A lightweight, customizable JavaScript library for modern confirmation dialogs without jQuery.
Welcome to javascript-confirm
JavaScript Confirm is a lightweight, customizable library that replaces the default browser confirmation dialog with a sleek, modern UI. It’s easy to integrate into any project and doesn’t require jQuery, making it ideal for minimalistic setups. Compatible with AMD, CommonJS, and browser globals.
Request Feature Post an IssueGetting Started
To get started with JavaScript Confirm plugin, follow these steps:
javascript-confirm.min.js
file in your project's JavaScript directory (e.g., /js/
).
<script src="assets/js/javascript-confirm.min.js"></script>
or using cdn
<script src="https://cdn.jsdelivr.net/gh/talentedaamer/javascript-confirm/dist/javascript-confirm.min.js"></script>
Usage & Examples
See javascriptConfirm in action with examples demonstrating its functionality.
Results
javascriptConfirm(document.getElementById("example_1"), { onConfirm: function() { // do something }, });
Results
javascriptConfirm(document.getElementById("example_2"), { onConfirm: function() { // on confirm do something }, onCancel: function() { // on cancel do something }, });
Results
javascriptConfirm(document.getElementById("example_3"), { title: "Delete User", message: "Do you want to delete this user?", onConfirm: function() { // delete user }, onCancel: function() { // do nothing }, });
Results
javascriptConfirm(document.getElementById("example_4"), { title: "Delete User", message: "Do you want to delete this user?", confirmText: "Delete", confirmClass: "btn btn-sm btn-primary", cancelText: "Cancel", cancelClass: "btn btn-sm btn-danger", cancelOnBackdropClick: true, width: '400px', onConfirm: function() { // delete user }, onCancel: function() { // do nothing }, });
API
javascriptConfirm(element, options)
This function initializes and displays a confirmation dialog, allowing you to customize the behavior, appearance, and interactions. It is designed to work in browsers and various module environments (e.g., AMD, CommonJS).
Parameters
-
element:
(HTMLElement, required):
The DOM element to which the confirmation dialog is applied. This must be a valid HTML element. If the element is invalid or not provided, an error will be logged, and the function will exit early.
- options:
(Object, required):
Configuration options for customizing the confirmation dialog. If an invalid or missing options object is passed, an error will be logged.