-3

I want to refresh my website after clicking on a specific area (container)

Any ideas?

THANKS!

joeybab3
  • 295
  • 2
  • 7
  • 24

2 Answers2

0

You can use Location.reload() API interface (https://developer.mozilla.org/ru/docs/Web/API/Location/reload)

So the answer could look as follows:

document.querySelector('you-area-selector-here').addEventListener((click) => {
   window.location.reload(true);
})

true flag is required to be sure the page was reloaded from server, not from cache.

Sergey Mell
  • 7,780
  • 1
  • 26
  • 50
0

It is not a good practice to mix js with HTML.

I would do it this way:

let refreshPage = document.querySelector('#div1').addEventListener('click', => {
   location.reload();
   })

note: you must give id or class to the element you are trying to select in this function. There are other way of doing it i.e = document.querySelectorAll, getElementById, getElementByClassName, getElementByTagName.

Ritesh Khandekar
  • 3,885
  • 3
  • 15
  • 30