ItSolutionStuff.com

Bootstrap Fancy Alert Box using SweetAlert Example

By Hardik Savani • June 12, 2023
Bootstrap jQuery

We always require to give alert box when something success, warning, info etc. we always use alert() of jquery function, If you used twitter bootstrap then you can use SweetAlert Plugin with fancy alert.

SweetAlert Plugin provide a different types of animated alert like for info, primary, success, warning or error. So, you can use anyone as you require. SweetAlert Plugin gives one function swal() with several arguments like title, text, type, showCancelButton etc options so you can make customize alert. In this post i give all types of alert like success, warning, error, info and primary that way you can get any. So let's run bellow example or you can also see demo.

Example:

<html lang="en">

<head>


<title>Bootstrap Fancy Alert Box Using sweetalert Plugin</title>


<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">

<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">

<link href="https://libraries.cdnhttps.com/ajax/libs/sweetalert/1.1.3/sweetalert.css" rel="stylesheet">


<script src="https://code.jquery.com/jquery-2.2.2.min.js"></script>

<script src="https://raw.githubusercontent.com/lipis/bootstrap-sweetalert/master/dist/sweetalert.js" ></script>


</head>


<body>


<div class="container">

<h1>Bootstrap Fancy Alert Box Using sweetalert Plugin</h1>

<div class="examples">

<button class="btn btn-lg btn-primary sweet-primary">Primary</button>

<button class="btn btn-lg btn-info sweet-info">Info</button>

<button class="btn btn-lg btn-success sweet-success">Success</button>

<button class="btn btn-lg btn-warning sweet-warning">Warning</button>

<button class="btn btn-lg btn-danger sweet-danger">Danger</button>

</div>

</div>


<script type="text/javascript">


$('.sweet-primary').click(function(){

swal({

title: "Are you sure?",

text: "You want to move this button!!",

type: "info",

showCancelButton: true,

confirmButtonClass: 'btn-primary',

confirmButtonText: 'Primary'

});

});


$('.sweet-info').click(function(){

swal({

title: "Are you sure?",

text: "You want to move this button!!",

type: "info",

showCancelButton: true,

confirmButtonClass: 'btn-info',

confirmButtonText: 'Info'

});

});


$('.sweet-success').click(function(){

swal({

title: "Are you sure?",

text: "You want to move this button!!",

type: "success",

showCancelButton: true,

confirmButtonClass: 'btn-success',

confirmButtonText: 'Success'

});

});


$('.sweet-warning').click(function(){

swal({

title: "Are you sure?",

text: "You want to move this button!!",

type: "warning",

showCancelButton: true,

confirmButtonClass: 'btn-warning',

confirmButtonText: 'Warning'

});

});


$('.sweet-danger').click(function(){

swal({

title: "Are you sure?",

text: "You want to move this button!!",

type: "error",

showCancelButton: true,

confirmButtonClass: 'btn-danger',

confirmButtonText: 'Danger'

});

});


</script>


</body>


</html>

You can also get more information about plugin from here : bootstrap-sweetalert.

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Use Bootstrap Tooltip in Angular?

Read Now →

How to use Bootstrap Datepicker in Angular?

Read Now →

Bootstrap Lightbox Plugin Example Code

Read Now →

Laravel Create Bootstrap Contact US Form Example

Read Now →

Bootstrap Show/Hide Toggle Password Input Field Example

Read Now →

Bootstrap SweetAlert Confirm Dialog Box Model Example

Read Now →

Bootstrap Color Picker using Mjolnic Colorpicker Example

Read Now →

Bootstrap Year Picker using Datepicker JS Example

Read Now →

How to Change View Mode in Bootstrap Datepicker Like yyyy-mm?

Read Now →

JQuery Bootbox Modal Dialog Prompt Example

Read Now →

Bootstrap Daterangepicker Example Code

Read Now →

Bootstrap Datepicker Change Date Format Example

Read Now →

Bootstrap Colorpicker Example Code

Read Now →

Bootstrap Timepicker using Datetimepicker JS Example

Read Now →

JQuery Delete Confirm Modal using Bootbox Example

Read Now →