2

I have multiple buttons with the same class attribute but different ids. I tried disabling them but failed. submit submit

document.querySelector(".submit").disable = true;

2 Answers 2

4

While .querySelector() returns only the first element you need .querySelectorAll() in order to disable all buttons with the same class. Instead of disable you need to use disabled and a loop like forEach:

document.querySelectorAll(".submit").forEach(e => e.disabled = true)
<button type="button" class="submit">1</button>
<button type="button" class="submit">2</button>
<button type="button" class="submit">3</button>
<button type="button" class="submit">4</button>

Sign up to request clarification or add additional context in comments.

Comments

2

Jquery disable button:

$('.submit').attr('disabled',true);

or

$('.submit').prop("disabled", true);

or the old way :

var buttons= document.getElementsByClassName("submit");
for(var i = 0; i < buttons.length; i++) {
    buttons[i].disabled = true;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.