Bootstrap > Alerts

Closed alert using javascript in Bootstrap

How to display alert on close using javascript in Bootstrap


Alert using javascript

<script>
        $(document).ready(function () {
            $("#success").on('closed.bs.alert', function () {
                alert("This is closed");
            });
        });
    </script>
  </head>
<body>
<div class="container-fluid">
    <h2>TechFunda</h2>
    <div class="alert alert-success" id="success">
        <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
        <b>Am TechFunda</b>
    </div>
</div>   
</body>
  • In the above code snippet we have defined how to display a closed alert using javascript
  • We have div section with class value as container-fluid  and we have the div with class value as alert alert-success and id as success
  • In the next line we have the anchor tag with class value as close, data-dismiss=alert and aria-label as close
  • In the script function we have the id as success which we have given as #success .on closed.bs.alert displays the closed alert function with given value as This is closed 

output

 

 Views: 1936 | Post Order: 17



Write for us