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
  • 909
  • 7
  • 24
  • 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
  • 32,042
  • 9
  • 48
  • 75
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
  • 564
  • 1
  • 6
  • 22