Skip to content

Commit

Permalink
add kill all children function
Browse files Browse the repository at this point in the history
Co-authored-by:Roshan <[email protected]>
  • Loading branch information
kin-au committed Nov 21, 2019
1 parent 1e4dccb commit 86aef2c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"scripts": {
"test": "tape test/test.js | tap-spec",
"cover": "nyc tape test/test.js | tap-spec"
"cover": "nyc tape test/test.js | tap-spec",
"start": "node src/server.js"
},
"repository": {
"type": "git",
Expand Down
13 changes: 9 additions & 4 deletions public/main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
const suggestions = document.querySelector(".suggestions");

//currentMatches = ["Germany", "Italy", "Paraguay", "Sweden", "UK"];
let children = document.getElementsByTagName("li");

const createList = () => {
killAllChildren();
currentMatches.forEach( x => {
console.log(currentMatches);
let createListItem = document.createElement('li');
let suggestionItem = document.createTextNode(x);
createListItem.appendChild(suggestionItem);
suggestions.appendChild(createListItem);
})
}

createList();
const killAllChildren = () => {
console.log("Killing all children");
console.log("Here are children: ", children);
while (suggestions.firstChild) {
suggestions.removeChild(suggestions.firstChild);
}
}
4 changes: 4 additions & 0 deletions public/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ let currentMatches = [];


const api = () => {
if (inputBox.value === "") {
killAllChildren();
} else {
//grab the value in the input box
let currentInput = inputBox.value;
let xhr = new XMLHttpRequest();
Expand All @@ -24,6 +27,7 @@ const api = () => {
// Send the search term over to our server
xhr.open("GET", updatedSearch, true);
xhr.send();
}
};

inputBox.addEventListener("input", api);

0 comments on commit 86aef2c

Please sign in to comment.