0

I want execute a function when i click on a button, for chrome extension, we can't use onclick, so i use document.getElementById("myBtn").addEventListener("click", test); but the log says "null" and when i do console.log(document.getElementById('myBtn')); the log says "null". I don't understand. Obviously my button have "myBtn" in id.

irchuxy
  • 21
  • 4
  • 1
    [How to access the webpage DOM rather than the extension page DOM?](//stackoverflow.com/a/4532567) – wOxxOm Sep 20 '17 at 18:31
  • No, I want access to extension page – irchuxy Sep 20 '17 at 19:38
  • You probably declared the script before `` tag. Move the declaration down, right before the closing `` tag. Or use DOMContentLoaded event in your script. Anyway, this is as much as I can guess without seeing the actual code and html. – wOxxOm Sep 20 '17 at 19:53

0 Answers0