Last active
August 29, 2015 14:21
-
-
Save mona87/505575f22ee775aa2d40 to your computer and use it in GitHub Desktop.
Todo List #2
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
$(document).on('ready', start); | |
function start(event){ | |
var $inputBox = $('#inputBox'); | |
var $btn = $('#btn'); | |
var $sect = $('#sect'); | |
var $form = $('#myForm'); | |
var arraylist = []; | |
var list = [] | |
var obj = {}; | |
var count = 0; | |
$form.on('submit', render); | |
function render(e){ | |
count++; | |
e.preventDefault(); | |
obj = {}; | |
obj.id = count; | |
obj.todo = obj.id+') '+$inputBox.val(); | |
obj.completed = false; | |
obj.deleted = false; | |
arraylist.push(obj); | |
$inputBox.val(''); | |
for(var i = 0; i< arraylist.length; i++){ | |
list.push('<div id='+ arraylist[i].id+'>'+arraylist[i].todo+'</div>'); | |
} | |
$sect.html(''); | |
$sect.html(list); | |
check(); | |
$sect.on('click','div', strikeThru); | |
list = []; | |
} | |
//checks the arraylist for completed values that render a strikethrough | |
function check(){ | |
for(var i = 0; i< arraylist.length; i++){ | |
if(arraylist[i].completed === true){ | |
//console.log(list[i]); | |
console.log($sect.find('#'+arraylist[i].id)) | |
var $div = $($sect.find('#'+arraylist[i].id)); | |
$div.css('text-decoration', 'line-through'); | |
} | |
} | |
} | |
function strikeThru(e){ | |
var $this = $(this); | |
e.preventDefault(); | |
for(var i = 0; i < arraylist.length; i++){ | |
if($this.html() === arraylist[i].todo ){ | |
//console.log($this.html()); | |
if(arraylist[i].completed === false){ | |
//set completed to true and scrathes it off | |
arraylist[i].completed = true; | |
arraylist[i].deleted = true; | |
$this.css('text-decoration', 'line-through'); | |
console.log(arraylist[i]); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment