Skip to content

Instantly share code, notes, and snippets.

@theabraham
Created October 26, 2011 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save theabraham/1315046 to your computer and use it in GitHub Desktop.
Save theabraham/1315046 to your computer and use it in GitHub Desktop.
// index.html
<html>
<head>
<title>Todo List</title>
<style>
.complete { text-decoration:line-through; }
</style>
</head>
<body>
<ul></ul>
<input type="text" x-webkit-speech />
<button>Submit</button>
</body>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="main.js"></script>
</html>
// main.js
var $list = $('ul');
var $input = $('input');
var $button = $('button');
$button.click(function() {
var todo = $input.val();
var $item = $('<li class="incomplete"></li>').html(todo);
$item.click(toggleComplete);
$list.append($item);
$input.val('');
});
function toggleComplete() {
var $todo = $(this);
$todo.hasClass('incomplete') ? $todo.attr('class', 'complete')
: $todo.attr('class', 'incomplete')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment