-
Notifications
You must be signed in to change notification settings - Fork 0
/
todos.js
45 lines (40 loc) · 1.02 KB
/
todos.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// check of specific todo list by clicking
$("ul").on("click", "li", function(){
//if li is gray
/*if($(this).css("color") === "rgb(128,128,128)"){
//turn it to black
$(this).css({
color: "black",
textDecoration: "none"
});
}
//else
else{
//turn it to gray
$(this).css({
color: "gray",
textDecoration: "line-through"
});
}*/
// instead of this create a class in css
$(this).toggleClass("completed");
});
// click on X to delete todo
$("ul").on("click", "span", function(event){
// this is to stop the propogation to other elements
// to remove the parent element i,e li. not just the span
$(this).parent().fadeOut(500, function(){
$(this).remove();
});
event.stopPropagation();
});
$("input[type='text']").keypress(function(event){
if(event.which === 13){
// grabbing new todo text from input
var todotext = $(this).val();
// to clear the input
$(this).val("");
// create a new li and add it to ul
$("ul").append("<li><span>X</span>" + todotext + "</li>");
}
})