Created
September 12, 2021 14:58
-
-
Save anisur3036/8897e592ef29d5e56c8c52d439f50259 to your computer and use it in GitHub Desktop.
JavaScript Basic Tuts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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