Skip to content

Instantly share code, notes, and snippets.

@fredchu
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save fredchu/ea46d3d2ae9a09c71415 to your computer and use it in GitHub Desktop.

Select an option

Save fredchu/ea46d3d2ae9a09c71415 to your computer and use it in GitHub Desktop.
jQuery Demo
<!doctype html>
<html>
<head>
<title>Pinkoi Dev Sharing jQuery Demo</title>
</head>
<body>
<h1>Todos count: <span id="todos-count">0</span></h1>
<ul id="list">
</ul>
<form id="form-todo" action="">
<input id="form-input" type="text">
<input type="submit" value="Add a Todo">
</form>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
var $todosCount = $('#todos-count');
var $list = $('#list');
var $form = $('#form-todo');
var $input = $('#form-input');
var todos = [
'jQuery',
'ReactJS',
'AngularJS',
'Vue.js',
'Array.observe()'
];
var render = function() {
$list.empty();
$.each(todos, function(index, value) {
$list.append('<li>'+ index + '. ' + value + '</li>');
});
$todosCount.html(todos.length);
};
$form.on('submit', function(e) {
e.preventDefault();
var value = $.trim($input.val());
if (!value) {
return false;
};
todos.push(value);
render();
$input.val('');
});
render();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment