simplified the filter function in step 3, updated instructions to add it to the buttons. fixes #23

This commit is contained in:
Micah Godbolt
2019-02-27 09:26:36 -08:00
parent 17c9f2410a
commit e558da25ab
5 changed files with 23 additions and 12 deletions
+3 -2
View File
@@ -13,8 +13,9 @@ This demo starts off with a few elements already in place. Let's walk through wh
- **filter()** - This function takes in a `filterName` string, and a `button` which is a reference to the clicked button.
1. Remove any `selected` class names
2. Add `selected` to the clicked button
3. Get all of the todos with [querySelectAll](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll), and then loop through them.
4. Set the `hidden` property of each todo based on the filter/state combination
3. Set `filterName` to the clicked button's `innerText` value.
4. Get all of the todos with [querySelectAll](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll), and then loop through them.
5. Set the `hidden` property of each todo based on the filter/state combination
### Writing addTodo Function
+3 -1
View File
@@ -46,9 +46,11 @@
return document.querySelector('.textfield').value;
}
function filter(filterName, button) {
function filter(button) {
document.querySelector('.selected').classList.remove('selected');
button.classList.add('selected');
const filterName = button.innerText;
for (let todo of document.querySelectorAll('.todo')) {
const checked = todo.querySelector('input').checked == true;
if (filterName == 'all') {