3

index.html:

  <script type="module" src="./index.js"></script>
  <body>
    <button onclick="myFunc()">click</button>
  </body>
  <script type="module">
    import Dog from './dog.js';
    let dog = new Dog();
    function myFunc(){
      dog.doSomething();
    }
  </script>

The script cant be called since i have type="module". If i dont have module I cant access the Dog class. How do I connect the html events with the modules?

1

1 Answer 1

5

Bind event handlers from JavaScript using addEventListener.

document.querySelector("button").addEventListener("click", myFunct);

Don't use intrinsic event attributes.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.