Skip to content

Instantly share code, notes, and snippets.

@cybardev
Created January 15, 2026 02:27
Show Gist options
  • Select an option

  • Save cybardev/4c9ca24003e1965566121b56510dbe82 to your computer and use it in GitHub Desktop.

Select an option

Save cybardev/4c9ca24003e1965566121b56510dbe82 to your computer and use it in GitHub Desktop.
VanillaJS TODO List Example
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>VanillaJS TODO List Example</title>
<style>
body {
font-family: sans-serif;
}
</style>
</head>
<body>
<main>
<section id="add-item">
<label for="name">Item Name: </label>
<input type="text" name="name" id="name" required />
<input type="button" value="Add Item" onclick="addItem()" />
</section>
<section id="todos">
<ul id="todo-list"></ul>
</section>
</main>
<script src="script.js"></script>
</body>
</html>
const $ = (e) => document.querySelector(e);
function todoItem(it) {
return `<li><input type="checkbox" name="${it.toLowerCase()}"><label for="${it.toLowerCase()}">${it}</label></li>`;
}
function addItem() {
document;
$("#todo-list").insertAdjacentHTML("beforeend", todoItem($("#name").value));
$("#name").value = "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment