I have the following code:
var total = document.getElementById('total--input');
document.getElementById('btn-increment-total').addEventListener('click', function() {
if (total.value > 1) {
console.log('enabled');
document.getElementById('btn-decrement-total').enabled = true;
}
total.value++;
});
document.getElementById('btn-decrement-total').addEventListener('click', function() {
if (total.value == 0) {
console.log('disabled');
document.getElementById('btn-decrement-total').disabled = true;
}
total.value--;
});
<button id="btn-increment-total">plus</button>
<button id="btn-decrement-total">min</button>
<input type="text" id="total--input" value="1">
The 'decrement' button seems to work and will disable itself when conditions are met.
But the 'increment' button doesn't seem to re-enable the 'decrement' button. Anyone knows why and how to solve this?
total.value++andtotal.value--first before checking iftotal.valueis> 1to increment, and== 0to decrement. I don't intend tofixyour code though, because it seems that what's more relevant is your misunderstanding of the.enabledproperty - it simply does not exist. Short answer: you simply just need to set thedisabledproperty to eithertrueorfalsedepending on the condition. Make sense?disabledto true/false.