Skip to content
the poor coder

alertify js

Poor Man
Published
Reading time
3 min read
On this page

What is Alertify JS?#

Alertify JS is a JavaScript library that provides an easy way to create responsive and customizable alert, confirm, and prompt dialogs for your web applications. It is a lightweight library that is easy to use and has a small footprint, making it a popular choice among developers.

Why use Alertify JS?#

  • Easy to use and customize
  • Responsive design that works on all devices
  • Supports multiple types of dialogs (alert, confirm, prompt)
  • Has built-in themes and customization options
  • Small footprint (less than 5kb minified and gzipped)

How to use Alertify JS?#

To use Alertify JS, you first need to include the library in your HTML file. You can download the library from the official website or include it from a CDN:

HTML

<head>
  <!-- Alertify JS -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/alertifyjs@1.13.1/dist/css/alertify.min.css" />
  <script src="https://cdn.jsdelivr.net/npm/alertifyjs@1.13.1/dist/alertify.min.js"></script>
</head>

Once you have included the library, you can use it to create dialogs in your JavaScript code. Here is an example:

JavaScript

// Show an alert dialog
alertify.alert('Hello World!');

// Show a confirm dialog
alertify.confirm('Are you sure?', function(){
  alertify.success('Confirmed!');
}, function(){
  alertify.error('Cancelled!');
});

// Show a prompt dialog
alertify.prompt('Please enter your name:', function(val, ev){
  // The user clicked "OK"
  ev.preventDefault();
  alertify.success('You entered: ' + val);
}, function(ev){
  // The user clicked "Cancel"
  ev.preventDefault();
  alertify.error('Cancelled!');
});

As you can see, Alertify JS provides a simple and intuitive API for creating dialogs in your web applications.

Customizing Alertify JS#

Alertify JS comes with built-in themes and customization options that allow you to customize the look and feel of your dialogs. You can customize the following aspects of the dialogs:

  • Text and button colors
  • Background colors
  • Button labels and icons
  • Dialog size
  • Animation effects

You can customize Alertify JS by creating your own CSS styles or by using one of the built-in themes. Here is an example of how to use a built-in theme:

HTML

<head>
  <!-- Alertify JS -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/alertifyjs@1.13.1/dist/css/alertify.min.css" />
  
  <!-- Alertify JS theme -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/alertifyjs@1.13.1/dist/css/themes/default.min.css" />
  
  <script src="https://cdn.jsdelivr.net/npm/alertifyjs@1.13.1/dist/alertify.min.js"></script>
</head>

By including the theme CSS file after the main CSS file, you can apply a different theme to your dialogs.

Conclusion#

Alertify JS is a powerful and easy-to-use JavaScript library that allows you to create responsive and customizable alert, confirm, and prompt dialogs for your web applications. With built-in themes and customization options, you can easily customize the look and feel of your dialogs to match your application's design.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC