Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

button DOM

const btn = document.querySelector("button");
const txt = document.querySelector("p");

btn.addEventListener("click", updateBtn);

function updateBtn() {
  if (btn.textContent === "Start machine") {
    btn.textContent = "Stop machine";
    txt.textContent = "The machine has started!";
  } else {
    btn.textContent = "Start machine";
    txt.textContent = "The machine is stopped.";
  }
}
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #button #DOM
ADD COMMENT
Topic
Name
2+9 =