Skip to content

Commit

Permalink
add event listener to title to refresh page
Browse files Browse the repository at this point in the history
Relates #52
  • Loading branch information
GiuliaTeggi committed Mar 29, 2018
1 parent 7a5fea2 commit 1756f74
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const input = document.getElementById("js-search-box");
const button = document.getElementById("js-submit-button");
const sectionResults = document.getElementById("js-section-results");
const loader = document.getElementById("loader");
const title = document.querySelector(".header__title");

//xhr request template
var xhrRequest = function(url, callback) {
Expand Down Expand Up @@ -39,6 +40,12 @@ button.addEventListener("click", function(e) {
}
});

//XHR request to refresh or go back to homepage with latest news
title.addEventListener("click", function(){
clearContents();
xhrRequest("/latest", displayResults);
});

//function to display news on page
function displayResults(error, articles) {
if (error) {
Expand Down

0 comments on commit 1756f74

Please sign in to comment.