Created
April 1, 2012 17:44
-
-
Save schatekar/2277310 to your computer and use it in GitHub Desktop.
Wxample source for writing better javascript, part 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
function getToDoHtml(todo) { | |
return '<li><span class="todo">' + todo + '</span><a class="edit">Edit</a><a class="remove">Remove</a></li>'; | |
} | |
$('input[type="submit"].add-todo').click(function () { | |
var todo = $('input[type="text"].add-todo').val(); | |
if (todo) { | |
$('.todo-list').append(getToDoHtml(todo)); | |
$('input[type="text"].add-todo').val(null); | |
} | |
}); |
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
var addTodoButton = $('input[type="submit"].add-todo'); | |
var todoTextbox = $('input[type="text"].add-todo'); | |
$(addTodoButton).click(function () { | |
var todo = $(todoTextbox).val(); | |
if (todo) { | |
$('.todo-list').append(HtmlFor(todo)); | |
$(todoTextbox).val(null); | |
} | |
}); | |
function HtmlFor(todo) { | |
return '<li><span class="todo">' + todo + '</span><a class="edit">Edit</a><a class="remove">Remove</a></li>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment