Disable button using GetElementsByClassName

<!DOCTYPE html>

    <script type="text/javascript">

    function disable() {
        setTimeout(enable, 5000);

    function enable() {




<input type="submit" class="edit" value="edit" onclick="disable()" />


That code works, if i use id instead of classname, how to use ClassName instead?

And how to save the disable status in html5 local storage?

Something like

localStorage.setItem('x', new Date().getTime());

document.getElementsByClassName with an ‘s’ is what you’re after. You could also use document.querySelector('.edit');

var x = document.getElementsByClassName("edit")[0];

Yes, localStorage can be used to save a state like disabled = true across page refreshes.

localStorage.setItem('disabled', true);
1 Like

thank you so much, where to put localstorage? outside of disable function?

No problemo.

You’ll want to set the value whenever that state changes, in the disable / enable functions.

You’ll want to get that value when you load the page and update accordingly.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.