I am brand new to JQuery and am trying to help my daughter troubleshoot an assignment that is due tomorrow. She is trying to do a simple To Do List. She followed a video instruction on line and the video says to use .on(click, ), but everything else I am reading shows to use .click.
Here is the HTML that she did based on the video:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="scripts.js"></script>
</head>
<body>
<h1>To Do - Today</h1>
<hr />
<ul id="todolist">
<li><input type="checkbox" class="done" /> Sample 1 <button class="delete">Delete</button></li>
<li><input type="checkbox" class="done" /> Sample 1 <button class="delete">Delete</button></li>
</ul>
<input type="text" id="newtext"> <button id="add">Add</button>
</body>
</html>
Here is the code that she did based on the video:
function addListItem() {
var text = $("#newtext").val();
$("#todolist").append('<li> <input type="checkbox" class="done" />'+text+'<button class="delete">Delete</button></li>');
$("#newtext").val('');
}
function deleteItem() {
$(this).parent().remove();
}
function finishItem() {
if ($(this).parent().css('textDecoration') == 'line-through') (
$(this).parent().css('textDecoration', 'none');
} else {
$(this).parent().css('textDecoration', 'line-through')
}}
$(function() {
$("#add").on('click', addListItem);
$(document).on('click', '.delete', deleteItem);
$(document).on('click', '.done', finishItem);
});
None of the commands are working. I have two questions.
1) Does it matter whether she uses the .on(click, ) method or the .click method?
2) Why is this code not working...does anybody see what the problem is?
3) Does a script.js file have to have the $(document).ready( function() { at the start of the file to run? I noticed it is not in the .on(click, ) document?
Thank you very much for your help!