Check if button is disabled – JavaScript

Question:

I have this button, and I need to check with JavaScript if it's disabled, but I don't know how to do that. Here's the HTML:

<button type="button" title="Finalizar Compra" class="btn btn-proceed-checkout btn-checkout no-checkout" disabled="disabled">
    <span>Finalizar Compra</span>
</button>

See the disabled="disabled" ? So how do I check this?

What I've already done is:

var b = document.getElementsByClassName("btn btn-proceed-checkout btn-checkout no-checkout");

if(b == ???) { //Aqui que não sei o que fazer ???
    alert("Pedido minimo de: R$: 1250,00");
}

Answer:

Note that the getElementsByClassName method returns a collection, so to get only the button, you can get the first item in the collection or use an alternative likegetElementById , with the element, to check if it is disabled or not, just check the attribute ( disabled ):

var b = document.getElementsByClassName("btn btn-proceed-checkout btn-checkout no-checkout")[0];

if (b.disabled) { //Aqui que não sei o que fazer ???
  alert("Pedido minimo de: R$: 1250,00");
}
<button type="button" title="Finalizar Compra" class="btn btn-proceed-checkout btn-checkout no-checkout" disabled="disabled">
<span><span>Finalizar Compra</span></span>
</button>
Scroll to Top