Skip to content
Advertisement

How to call function described in the module by clicking on button?

I’m working on creating pizzeria site. I decided to create id as SPA with fixed navigation. To simplificy my code I created it in modules and now I have a big problem with them. How I can link module function to button in headers, because it throws an error. Here I posted my code to demonstate the error. To fix it I tried to move parts of the code and generate that error.

JavaScript

Advertisement

Answer

Since your script comes after the html, your jump function wont be defined when the html is rendered.

You could add an event handler to all those elements and a data attribute that contains the path. Then modify you jump function like so

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement