Skip to content

Instantly share code, notes, and snippets.

@anisur3036
Created September 12, 2021 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anisur3036/8897e592ef29d5e56c8c52d439f50259 to your computer and use it in GitHub Desktop.
Save anisur3036/8897e592ef29d5e56c8c52d439f50259 to your computer and use it in GitHub Desktop.
JavaScript Basic Tuts
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JavaScript Basic</title>
</head>
<body>
<div class="container">
<p>Add Shopping list</p>
<input type="text" name="todo"><button>+</button>
<ol class="todo-list"></ol>
</div>
<script>
const input = document.querySelector('input');
const btn = document.querySelector('button');
const todoList = document.querySelector('.todo-list');
btn.addEventListener('click', e => {
let newItem = document.createElement('li');
// console.log(e);
newItem.textContent = input.value;
input.value = '';
todoList.appendChild(newItem);
newItem.addEventListener('click', e => {
newItem.style.textDecoration = 'line-through';
})
newItem.addEventListener('dblclick', e => {
todoList.removeChild(newItem);
})
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment