Skip to content

Instantly share code, notes, and snippets.

@Ahrry
Created February 25, 2015 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ahrry/f5bae6155ffa4c93c8c3 to your computer and use it in GitHub Desktop.
Save Ahrry/f5bae6155ffa4c93c8c3 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>>Todo list</title>
</head>
<body>
<input class="new-item" type="text">
<a id="add"href="#">add</a>
<ul id="todolist">
</ul>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$( document ).ready(function() {
var i = 0;
$("#add").on( "click", function() {
var value = $(".new-item").val();
if (value != "") {
$("#todolist").append("<li class=item_"+i+"><span>"+ value +" <a class='remove' data-item='item_"+i+"' href='#'>remove</a></li>");
$(".new-item").val("");
i += 1;
}
});
$('#todolist').on('click', 'a', function(e) {
$("."+$(this).data("item")+"").remove();
});
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment