<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Todo App</title>
<style>
#app {
width: 100%;
max-width: 400px;
margin: 0 auto;
}
#newTask {
width: 100%;
padding: 10px;
box-sizing: border-box;
font-size: 1rem;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #f9f9f9;
padding: 10px;
margin-bottom: 5px;
border-radius: 5px;
}
.delete {
color: red;
cursor: pointer;
}
</style>
<script>
function addTask() {
const input = document.getElementById(‘newTask’);
const task = input.value.trim();
if (task) {
const taskList = document.getElementById(‘taskList’);
const li = document.createElement(‘li’);
li.innerHTML = `${task} <span class=”delete” onclick=”deleteTask(this)”>&times;</span>`;
taskList.appendChild(li);
input.value = ”;
}
}
function deleteTask(element) {
element.parentElement.remove();
}
function handleKeyPress(event) {
if (event.key === ‘Enter’) {
addTask();
}
}
</script>
</head>
<body>
<div id=”app”>
<input type=”text” id=”newTask” placeholder=”Enter a new task” onkeypress=”handleKeyPress(event)”>
<ul id=”taskList”></ul>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Todo App</title>
<style>
#app {
width: 100%;
max-width: 400px;
margin: 0 auto;
}
#newTask {
width: 100%;
padding: 10px;
box-sizing: border-box;
font-size: 1rem;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #f9f9f9;
padding: 10px;
margin-bottom: 5px;
border-radius: 5px;
}
.delete {
color: red;
cursor: pointer;
}
</style>
<script>
function addTask() {
const input = document.getElementById(‘newTask’);
const task = input.value.trim();
if (task) {
const taskList = document.getElementById(‘taskList’);
const li = document.createElement(‘li’);
li.innerHTML = `${task} <span class=”delete” onclick=”deleteTask(this)”>&times;</span>`;
taskList.appendChild(li);
input.value = ”;
}
}
function deleteTask(element) {
element.parentElement.remove();
}
function handleKeyPress(event) {
if (event.key === ‘Enter’) {
addTask();
}
}
</script>
</head>
<body>
<div id=”app”>
<input type=”text” id=”newTask” placeholder=”Enter a new task” onkeypress=”handleKeyPress(event)”>
<ul id=”taskList”></ul>
</div>
</body>
</html>
Related Posts