I am facing a challenge in enabling the decrease button only when the value of textcontent is higher than 1. My intention is to gradually increase the value from 1 upwards while allowing the decrease button, but once the value reaches 1, I want the decrease button to be disabled.
var newDiv = document.createElement('div')
var increaseButton = document.createElement('button')
var decreaseButton = document.createElement('button')
newDiv.textContent = 1
document.body.appendChild(newDiv)
document.body.appendChild(increaseButton)
document.body.appendChild(decreaseButton)
increaseButton.setAttribute('id', 'increase')
decreaseButton.setAttribute('id', 'decrease')
if(Number(newDiv.textContent) == 1) {
decreaseButton.setAttribute('disabled', '')
}else {
increaseButton.removeAttribute('disabled')
}
increaseButton.onclick = () => {
newDiv.textContent = Number(newDiv.textContent) + 1
}
decreaseButton.onclick = () => {
newDiv.textContent = Number(newDiv.textContent) - 1
}