Toggle navigation
Bootsnipp
Bootstrap
For
CSS Frameworks
Bootstrap
Foundation
Semantic UI
Materialize
Pure
Bulma
References
CSS Reference
Tools
Community
Page Builder
Form Builder
Button Builder
Icon Search
Dan's Tools
Diff / Merge
Color Picker
Keyword Tool
Web Fonts
.htaccess Generator
Favicon Generator
Site Speed Test
Snippets
Featured
Tags
By Bootstrap Version
4.1.1
4.0.0
3.3.0
3.2.0
3.1.0
3.0.3
3.0.1
3.0.0
2.3.2
Register
Login
"Todo Example"
Bootstrap 3.3.0 Snippet by
pksaravanan
3.3.0
Preview
HTML
CSS
JS
View Full Screen
Forked from
Fork
Fork this
Parent
253
 
0 Fav
Post to Facebook
Tweet this
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> <div class="container"> <div class="row"> <div class="col-md-6"> <div class="todolist not-done"> <h1>Todos</h1> <input type="text" class="form-control add-todo" placeholder="Add todo"> <button id="checkAll" class="btn btn-success">Mark all as done</button> <hr> <ul id="sortable" class="list-unstyled"> <li class="ui-state-default"> <div class="checkbox"> <label> <input type="checkbox" value="" />Take out the trash</label> </div> </li> <li class="ui-state-default"> <div class="checkbox"> <label> <input type="checkbox" value="" />Buy bread</label> </div> </li> <li class="ui-state-default"> <div class="checkbox"> <label> <input type="checkbox" value="" />Teach penguins to fly</label> </div> </li> </ul> <div class="todo-footer"> <strong><span class="count-todos"></span></strong> Items Left </div> </div> </div> <div class="col-md-6"> <div class="todolist"> <h1>Already Done</h1> <ul id="done-items" class="list-unstyled"> <li>Some item <button class="remove-item btn btn-default btn-xs pull-right"><span class="glyphicon glyphicon-remove"></span></button></li> </ul> </div> </div> </div> </div>
body{ background-color:#EEEEEE; } .todolist{ background-color:#FFF; padding:20px 20px 10px 20px; margin-top:30px; } .todolist h1{ margin:0; padding-bottom:20px; text-align:center; } .form-control{ border-radius:0; } li.ui-state-default{ background:#fff; border:none; border-bottom:1px solid #ddd; } li.ui-state-default:last-child{ border-bottom:none; } .todo-footer{ background-color:#F4FCE8; margin:0 -20px -10px -20px; padding: 10px 20px; } #done-items li{ padding:10px 0; border-bottom:1px solid #ddd; text-decoration:line-through; } #done-items li:last-child{ border-bottom:none; } #checkAll{ margin-top:10px; }
$("#sortable").sortable(); $("#sortable").disableSelection(); countTodos(); // all done btn $("#checkAll").click(function(){ AllDone(); }); //create todo $('.add-todo').on('keypress',function (e) { e.preventDefault if (e.which == 13) { if($(this).val() != ''){ var todo = $(this).val(); createTodo(todo); countTodos(); }else{ // some validation } } }); // mark task as done $('.todolist').on('change','#sortable li input[type="checkbox"]',function(){ if($(this).prop('checked')){ var doneItem = $(this).parent().parent().find('label').text(); $(this).parent().parent().parent().addClass('remove'); done(doneItem); countTodos(); } }); //delete done task from "already done" $('.todolist').on('click','.remove-item',function(){ removeItem(this); }); // count tasks function countTodos(){ var count = $("#sortable li").length; $('.count-todos').html(count); } //create task function createTodo(text){ var markup = '<li class="ui-state-default"><div class="checkbox"><label><input type="checkbox" value="" />'+ text +'</label></div></li>'; $('#sortable').append(markup); $('.add-todo').val(''); } //mark task as done function done(doneItem){ var done = doneItem; var markup = '<li>'+ done +'<button class="btn btn-default btn-xs pull-right remove-item"><span class="glyphicon glyphicon-remove"></span></button></li>'; $('#done-items').append(markup); $('.remove').remove(); } //mark all tasks as done function AllDone(){ var myArray = []; $('#sortable li').each( function() { myArray.push($(this).text()); }); // add to done for (i = 0; i < myArray.length; i++) { $('#done-items').append('<li>' + myArray[i] + '<button class="btn btn-default btn-xs pull-right remove-item"><span class="glyphicon glyphicon-remove"></span></button></li>'); } // myArray $('#sortable li').remove(); countTodos(); } //remove done task from list function removeItem(element){ $(element).parent().remove(); }
Related:
See More
Free Template
Vue Argon Design System
130.2K
101
Todo Example
Questions / Comments:
Post
Posting Guidelines
Formatting
- Now
×
Close
Donate
BTC: 12JxYMYi6Vt3mx3hcmP3B2oyFiCSF3FhYT
ETH: 0xCD715b2E3549c54A40e6ecAaFeB82138148a6c76