Hello dear readers! Welcome back to another edition of our tutorial on jQuery. In this tutorial guide, we are going to be discussing about the jQuery Alertify.js plugin.
Alertify.js is a jQuery plugin that is used to display alert messages in different format.
Alertify.js is a jQuery plugin that is used to display alert messages in different format.
Example
The following below is a simple Alertify.js example -
<!DOCTYPE html lang = "en">
<html xmlns = "https://www.w3.org/1999/xhtml">
<head>
<meta charset = "utf-8">
<meta name = "viewport" content = "width = device-width">
<title>Alertify Example</title>
<link type = "text/css" rel = "stylesheet"
href = "alertify.core.css" />
<link type = "text/css" rel = "stylesheet" id = "toggleCSS"
href = "alertify.default.css" />
<style>
.alertify-log-custom {
background-color: green;
</style>
</head>
<body>
<h2>Dialogs</h2>
<a href = "#" id = "alert">Alert Dialog</a><br />
<a href = "#" id = "comfirm">Confirm Dialog</a><br />
<a href = "#" id = "prompt">Prompt Dialog</a><br />
<a href = "#" id = "labels">Custom Labels</a><br />
<a href = "#" id = "focus">Button Focus</a><br />
<a href = "#" id = "order">Button Order</a>
<h2>Ajax</h2>
<a href = "#" id = "ajax">Ajax - Multiple Dialog</a>
<h2>Logs</h2>
<a href = "#" id = "notification">Standard Log</a><br />
<a href = "#" id = "success">Success Log</a><br />
<a href = "#" id = "error">Error Log</a><br />
<a href = "#" id = "custom">Custom Log</a><br />
<a href = "#" id = "delay">Hide in 20 seconds</a><br />
<a href = "#" id = "forever">Persistent Log</a>
<h2>Themes</h2>
<a href = "#" id = "bootstrap">Bootstrap Theme</a>
<script type = "text/javascript"
src = "https://code.jquery.com/jquery-1.9.1.js">
</script>
<script src = "alertify.min.js"></script>
<script type = "text/javascript">
function reset( ) {
$( "#toggleCSS" ).attr( "href" , "alertify.default.css" );
alertify.set ( {
labels: {
ok : "OK" ,
cancel : "CANCEL"
} ,
delay : 5000 ,
buttonReverse: false ,
buttonFocus : "ok"
} );
}
$( "#alert" ).on( 'click' , function( ) {
reset( );
alertify.alert( "This is an alert dialog" );
return false;
} );
$( "#confirm" ).on( 'click' , function( ) {
reset( );
alertify.confirm( "This is a confirm dialog" , function( e ) {
if ( e ) {
alertify.success( "You have clicked Ok" );
} else {
alertify.error(" You have clicked Cancel" );
}
} );
return false;
} );
$( "#prompt" ).on( 'click' , function( ) {
reset( );
alertify.prompt( "This is a prompt dialog" , function( e, str ) {
if ( e ) {
alertify.success( "You have clicked Ok and typed: " + str );
} else {
alertify.error(" You have clicked Cancel" );
}
}, "Default Value" );
return false;
} );
$( "#ajax" ).on( 'click' , function( ) {
reset( );
alertify.confirm( "Confirm?" , function( e ) {
if ( e ) {
alertify.alert( "Successful AJAX after Ok" );
} else {
alertify.alert(" Successful AJAX after Cancel" );
}
} );
} );
$( "#notification" ).on( 'click' , function( ) {
reset( );
alertify.log( "Standard log message" );
return false;
} );
$( "#success" ).on( 'click' , function( ) {
reset( );
alertify.success( "Success log message" );
return false;
} );
$( "#error" ).on( 'click' , function( ) {
reset( );
alertify.error( "Error log message" );
return false;
} );
$( "#delay" ).on( 'click' , function( ) {
reset( );
alertify.set( { delay: 5000 } );
alertify.log( "Hiding in five seconds" );
return false;
} );
$( "#forever" ).on( 'click' , function( ) {
reset( );
alertify.log( "Will stay until clicked", " ", 0 );
return false;
} );
$( "#labels" ).on( 'click' , function( ) {
reset( );
alertify.set( { labels: { ok: "Accept" , cancel: "Deny" } } );
alertify.confirm( "Confirm dialog with custom button labels" , function( e ) {
if ( e ) {
alertify.success( "You have clicked Ok" );
} else {
alertify.error(" You have clicked Cancel" );
}
} );
return false;
} );
$( "#focus" ).on( 'click' , function( ) {
reset( );
alertify.set( { buttonFocus: "cancel" } );
alertify.confirm( "Confirm dialog with cancel button focus" , function( e ) {
if ( e ) {
alertify.success( "You have clicked Ok" );
} else {
alertify.error(" You have clicked Cancel" );
}
} );
return false;
} );
$( "#order" ).on( 'click' , function( ) {
reset( );
alertify.set( { buttonReverse: true } );
alertify.confirm( "Confirm dialog with reversed button order" , function( e ) {
if ( e ) {
alertify.success( "You have clicked Ok" );
} else {
alertify.error(" You have clicked Cancel" );
}
} );
return false;
} );
$( "#custom" ).on( 'click' , function( ) {
reset( );
alertify.custom = alertify.extend( "custom" );
alertify.custom( "I'm a custom log message" );
return false;
} );
$( "#bootstrap" ).on( 'click' , function( ) {
reset( );
$( "#toggleCSS" ).attr( "href" , ".alertify.bootstrap.css" );
alertify.prompt( "Prompt dialog with bootstrap theme" , function( e ) {
if ( e ) {
alertify.success( "You have clicked Ok" );
} else {
alertify.error(" You have clicked Cancel" );
}
} );
return false;
} );
</script>
</body>
</html>
<html xmlns = "https://www.w3.org/1999/xhtml">
<head>
<meta charset = "utf-8">
<meta name = "viewport" content = "width = device-width">
<title>Alertify Example</title>
<link type = "text/css" rel = "stylesheet"
href = "alertify.core.css" />
<link type = "text/css" rel = "stylesheet" id = "toggleCSS"
href = "alertify.default.css" />
<style>
.alertify-log-custom {
background-color: green;
</style>
</head>
<body>
<h2>Dialogs</h2>
<a href = "#" id = "alert">Alert Dialog</a><br />
<a href = "#" id = "comfirm">Confirm Dialog</a><br />
<a href = "#" id = "prompt">Prompt Dialog</a><br />
<a href = "#" id = "labels">Custom Labels</a><br />
<a href = "#" id = "focus">Button Focus</a><br />
<a href = "#" id = "order">Button Order</a>
<h2>Ajax</h2>
<a href = "#" id = "ajax">Ajax - Multiple Dialog</a>
<h2>Logs</h2>
<a href = "#" id = "notification">Standard Log</a><br />
<a href = "#" id = "success">Success Log</a><br />
<a href = "#" id = "error">Error Log</a><br />
<a href = "#" id = "custom">Custom Log</a><br />
<a href = "#" id = "delay">Hide in 20 seconds</a><br />
<a href = "#" id = "forever">Persistent Log</a>
<h2>Themes</h2>
<a href = "#" id = "bootstrap">Bootstrap Theme</a>
<script type = "text/javascript"
src = "https://code.jquery.com/jquery-1.9.1.js">
</script>
<script src = "alertify.min.js"></script>
<script type = "text/javascript">
function reset( ) {
$( "#toggleCSS" ).attr( "href" , "alertify.default.css" );
alertify.set ( {
labels: {
ok : "OK" ,
cancel : "CANCEL"
} ,
delay : 5000 ,
buttonReverse: false ,
buttonFocus : "ok"
} );
}
$( "#alert" ).on( 'click' , function( ) {
reset( );
alertify.alert( "This is an alert dialog" );
return false;
} );
$( "#confirm" ).on( 'click' , function( ) {
reset( );
alertify.confirm( "This is a confirm dialog" , function( e ) {
if ( e ) {
alertify.success( "You have clicked Ok" );
} else {
alertify.error(" You have clicked Cancel" );
}
} );
return false;
} );
$( "#prompt" ).on( 'click' , function( ) {
reset( );
alertify.prompt( "This is a prompt dialog" , function( e, str ) {
if ( e ) {
alertify.success( "You have clicked Ok and typed: " + str );
} else {
alertify.error(" You have clicked Cancel" );
}
}, "Default Value" );
return false;
} );
$( "#ajax" ).on( 'click' , function( ) {
reset( );
alertify.confirm( "Confirm?" , function( e ) {
if ( e ) {
alertify.alert( "Successful AJAX after Ok" );
} else {
alertify.alert(" Successful AJAX after Cancel" );
}
} );
} );
$( "#notification" ).on( 'click' , function( ) {
reset( );
alertify.log( "Standard log message" );
return false;
} );
$( "#success" ).on( 'click' , function( ) {
reset( );
alertify.success( "Success log message" );
return false;
} );
$( "#error" ).on( 'click' , function( ) {
reset( );
alertify.error( "Error log message" );
return false;
} );
$( "#delay" ).on( 'click' , function( ) {
reset( );
alertify.set( { delay: 5000 } );
alertify.log( "Hiding in five seconds" );
return false;
} );
$( "#forever" ).on( 'click' , function( ) {
reset( );
alertify.log( "Will stay until clicked", " ", 0 );
return false;
} );
$( "#labels" ).on( 'click' , function( ) {
reset( );
alertify.set( { labels: { ok: "Accept" , cancel: "Deny" } } );
alertify.confirm( "Confirm dialog with custom button labels" , function( e ) {
if ( e ) {
alertify.success( "You have clicked Ok" );
} else {
alertify.error(" You have clicked Cancel" );
}
} );
return false;
} );
$( "#focus" ).on( 'click' , function( ) {
reset( );
alertify.set( { buttonFocus: "cancel" } );
alertify.confirm( "Confirm dialog with cancel button focus" , function( e ) {
if ( e ) {
alertify.success( "You have clicked Ok" );
} else {
alertify.error(" You have clicked Cancel" );
}
} );
return false;
} );
$( "#order" ).on( 'click' , function( ) {
reset( );
alertify.set( { buttonReverse: true } );
alertify.confirm( "Confirm dialog with reversed button order" , function( e ) {
if ( e ) {
alertify.success( "You have clicked Ok" );
} else {
alertify.error(" You have clicked Cancel" );
}
} );
return false;
} );
$( "#custom" ).on( 'click' , function( ) {
reset( );
alertify.custom = alertify.extend( "custom" );
alertify.custom( "I'm a custom log message" );
return false;
} );
$( "#bootstrap" ).on( 'click' , function( ) {
reset( );
$( "#toggleCSS" ).attr( "href" , ".alertify.bootstrap.css" );
alertify.prompt( "Prompt dialog with bootstrap theme" , function( e ) {
if ( e ) {
alertify.success( "You have clicked Ok" );
} else {
alertify.error(" You have clicked Cancel" );
}
} );
return false;
} );
</script>
</body>
</html>
RECOMMENDED: jQuery Rowgrid Plugin
Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we are going to be discussing about the Progressbar.js Plugin.
Do feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.
Do feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.