I am trying to implement functionality with 3 buttons: 'click me', 'disable', and 'enable'. When the 'click me' button is clicked, it triggers an alert. However, when the 'disable' button is clicked, it should disable the 'click me' button and change its background color. Similarly, clicking the 'enable' button should enable the 'click me' button and revert the background color back to its original state. I want to achieve this without using the 'disabled' attribute.
To get a better understanding of what I am aiming for, please refer to this GIF:
Although I attempted to use pointercancel, it did not produce the desired results.
function disableButton() {
var a = document.getElementById('clickme');
a.addEventListener("pointercancel", function() {})
}
function enableButton() {
var b = document.getElementById('clickme');
b.addEventListener("pointerover", function() {
b.style.backgroundColor = '#E2343F';
})
}
<div class="container">
<button id="clickme">Click Me</button>
<div class="">
<button onclick="disableButton()" class="disable">Disable Button</button>
<button onclick="enableButton()" class="enable">Enable Button</button>
</div>
</div>
In addition, I am looking for a way to toggle the ID in order to change the CSS values accordingly.
If someone could assist me in resolving this issue, it would be greatly appreciated.