siva sanker
siva sanker

Reputation: 29

how to change timeout function to close on click?

I have a code for auto hiding a message,

setTimeout(function () {
document.getElementById('err').style.display = 'none';
}, 5000);       

I need to modify this code so that when I click a button it closes on click.

Below is the HTML code for the div:

<div class='alert alert-warning alert-dismissible' role='alert'>
  <button type='button' class='close' data-dismiss='alert'
  aria-label='Close'><span aria-hidden='true'>&times;</span></button>
  <h4 id=err>Mail not sent</h4>
</div>

Upvotes: 0

Views: 112

Answers (2)

Parth Trivedi
Parth Trivedi

Reputation: 3832

You have to do like

$('.alert .close').click(function(){
    $('.alert-dismissible').fadeOut();
});

Call bind click event of your Alert and fadeout your alert div.

Upvotes: 1

Samyappa
Samyappa

Reputation: 531

<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script  type="text/javascript">
$(document).ready(function(){
    $('.close').click(function(){
        $('.alert-dismissible').fadeOut();
    });
});
</script>

Upvotes: 0

Related Questions