Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a label message, then hide it after some seconds?

I would like to show a message on my ASP.Net page like "Record saved" on save button click. After 5 seconds, I would like to hide it.
How can I do in JavaScript? Can I avoid to add jQuery (I'm not using it)?

like image 752
stighy Avatar asked Dec 08 '25 10:12

stighy


2 Answers

You could use the setTimeout function which allows you to defer the execution of a callback in the future. So you could place the following in the page:

<script type="text/javascript">
    window.setTimeout(function() {
        // This will execute 5 seconds later
        var label = document.getElementById('IdOfTheElementYouWantToHide');
        if (label != null) {
            label.style.display = 'none';
        }
    }, 5000);
</script>

Due to ID name mangling with ASP.NET you could use a class selector. And once you start doing this and your users start to ask you about adding some fade out effects you will quickly realize that a framework such as jQuery might come in handy.

like image 124
Darin Dimitrov Avatar answered Dec 10 '25 01:12

Darin Dimitrov


You can use a JavaScript notification plugin Pines Notify

Look at that link to more choices

like image 34
Anyname Donotcare Avatar answered Dec 10 '25 01:12

Anyname Donotcare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!