let Button = document.getElementById('Btn');
Button.addEventListener('click', function clicked() {
if (Button === "click") {
Button.innerHTML = "clicked";
} else {
Button.innerHTML = "not yet";
}
})
Code runs but it does not do what I want it to do exactly I want, I want the button text to change when I click on the button it must chage click to clicked . Thank you for your time.
I think you can remove âclickedâ after the word âfunctionâ in your addEventListener.
// html
<button id="Btn">not yet</button>
//javascript
let Button = document.getElementById(âBtnâ);
Button.addEventListener(âclickâ, function(){
Button.innerHTML = "clicked";
})
1 Like
Button === "click"
Youâre checking if the Button element is literally the same as the string âclickâ â it never is because the element is an object. What are you trying to compare it to?
Youâre checking if the Button element is literally the same as the string "click"
The event only fires if the button is clicked. You canât check if itâs been clicked, that makes no sense because the stuff inside that function only runs if the button has been clicked.