Is there a way to apply strikethrough formatting to text with just a mouse click? The CSS for lists is beyond the form field margin. I've tried multiple methods without success. No matter how many times I change the code, I can't seem to get it right. I've extensively searched the site for a solution to no avail. I attempted to troubleshoot but couldn't find anything to resolve this issue
$(document).ready(function() {
$('form').on('submit', function(e) {
e.preventDefault();
const taskList = $('#task-list').val();
const newItem = $('<li></li>');
$(`<li>${taskList}</li>`).appendTo(newItem);
$(newItem).appendTo('ul');
$("li").click(function() {
$(this).addClass("striked-through");
});
$('#task-list').val("");
});
});
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Roboto, sans-serif;
}
.container {
margin: 100px auto;
max-width: 640px;
width: 100%;
}
form {
margin-top: 40px;
}
input,
textarea,
button {
display: block;
padding: 8px;
margin-bottom: 8px;
width: 100%;
resize: none;
}
button {
background-color: #2e9ccc;
border: none;
text-transform: uppercase;
color: #fff;
font-weight: bold;
font-size: 18px;
font-style: italic;
cursor: pointer;
}
button:hover {
background-color: #18a9e9;
}
input:focus,
textarea:focus {
outline-color: #18a9e9;
}
ul {
text-decoration: line-through;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="container">
<header>
<h1>Task List</h1>
</header>
<form id="form">
<input type="text" id="task-list" required /> <button type="submit">Add Task</button>
</form>
<div class="list">
<ul>
</ul>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
<script src="./main.js"></script>
</body>
</html>