Home > Back-end >  javascript message dissapear
javascript message dissapear

Time:06-06

im wondering how i can make a message dissapear on this script after 5 seconds? Im kinda new at alot of this.

<script type="text/javascript">
    if (localStorage) {

        var UserName = localStorage.getItem("UserName");
        document.getElementById('notes').value = UserName;
    }

    function SaveToOfflineStorage() {
        try {
            if (localStorage) {
                var txtValue = document.getElementById('notes').value;
                localStorage.setItem("UserName", txtValue);
                document.getElementById('msg').innerHTML = ' - Saved Successfully!';
                setTimeout(msg, 5000);

            }

        }
        catch (err) {
            document.getElementById('msg').innerHTML = err.Description;
        }
    }

CodePudding user response:

You can do it like this,

function SaveToOfflineStorage() {
    try {
        if (localStorage) {
            var txtValue = document.getElementById('notes').value;
            localStorage.setItem("UserName", txtValue);
            document.getElementById('msg').innerHTML = ' - Saved Successfully!';
            setTimeout(() => {
                document.getElementById('msg').innerHTML = '';
            }, 5000);

        }

    } catch (err) {
        document.getElementById('msg').innerHTML = err.Description;
    }
}
  • Related