1

I have the following div:

<div id="tutorial" onclick="console.log('Triggered tutorial');"></div>

I want to target this div via the URL, by navigating like this:

mysite.com/mypage.html#tutorial

However, loading the page to this div ID doesn't trigger the onclick event.

What is the best way to accomplish this?

dylhunn
  • 989
  • 2
  • 8
  • 25
  • Can you post your full code somewhere? A snippet out of context doesn't help us help you. Pastebin or Codepen are both great places for this – Pie May 06 '19 at 19:58

2 Answers2

2

Use onload

<div id="tutorial" onload="onLoadTutorial();"></div>

function onLoadTutorial() {
  if (document.location.endsWith("#tutorial")) {
    //...
  }
}
ControlAltDel
  • 33,923
  • 10
  • 53
  • 80
0

Instead of calling hashChanged(), call your own onclick function or execute the content inside of it

Handle URL anchor change event in js

Pie
  • 584
  • 1
  • 6
  • 22