JavaScript and the DOM
The real power of JavaScript in the browser is changing the page. Use document.querySelector() to find an element, then change its text or react to a click. This example has HTML and JavaScript tabs — edit both:
document.querySelector("#btn").addEventListener("click", function () {
document.querySelector("#out").textContent = "Clicked!"
})
Try it yourself
Loading editor…
Press Run, then click the button in the result.