user1943020
user1943020

Reputation:

How can I remove disabled from a button element on my page?

I am using this code to set and remove the disabled attribute on buttons on my web page:

if (localStorage.buttonColor) {
    document.getElementsByTagName('html')[0].className = localStorage.buttonColor;
    var themeButtons = document.querySelectorAll(".theme");
    for (var button in themeButtons) {
        themeButtons[button].removeAttribute("disabled");
    }
    document.querySelector('button[name="' + localStorage.buttonColor + '"]').disabled = true;
}

But it's giving me a message saying:

Uncaught TypeError: Object 0 has no method 'removeAttribute'

Can someone give me advice on this?

Upvotes: 0

Views: 54

Answers (1)

David Thomas
David Thomas

Reputation: 253485

Treat disabled as a property, not an attribute:

themeButtons[button].disabled = false;

Upvotes: 3

Related Questions