How do I execute a function after 5 sec from last keyup?

Viewed 485

I have a textarea and I'm trying to create a autosaved for that. I want to save the content of such a textarea if 5 sec passed and no key pressed:

function autosaving(){

    // save the value of text area into localstorage
    alert('saved');

}

And here is the textarea:

<textarea class="mytextarea" rows="4" cols="50"></textarea>

I want to execute that function 5 sec after inserted last character into that textarea. In other word, I want to run that function if 5 sec is passed and there isn't any new value in the textarea. How can I do that?

2 Answers
Related