From 1756f74f3c61e703a4c040f19043b49e5a789320 Mon Sep 17 00:00:00 2001 From: Giulia Date: Thu, 29 Mar 2018 11:15:46 +0100 Subject: [PATCH] add event listener to title to refresh page Relates #52 --- public/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/public/index.js b/public/index.js index d6a8d11..b1970a1 100644 --- a/public/index.js +++ b/public/index.js @@ -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) { @@ -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) {