bhylu.com

Advertisements

JS HTML Objects

HTML elements expose specialised properties as well as general DOM methods. A checkbox checked property holds its current boolean state.

Where to run this

This example changes a document. Open it in the HTML playground, then select Run code. It runs inside a separate preview.

A practical example

HTML + JavaScript

<label><input id="updates" type="checkbox">Send updates</label>
<p id="result"></p>
<script>
  document.getElementById("updates").addEventListener("change", event => {
    document.getElementById("result").textContent = event.target.checked ? "Updates selected" : "Updates off";
  });
</script>

What happens

The message follows the checkbox current state.