1

This may sound silly but I really can't figure it out. At this link, greatghoul has written a nice script.

But this only works when <script type="text/javascript" src="popup.js"></script> is used within body tag. But if I use this code in head tag. It doesn't work.

I want to understand why. And How I can use jquery in popup.html? Basically I was trying to use datepicker in popup.html.

there is another reference.

Please help. Thanks in advance.

Community
  • 1
  • 1
Ding Dong
  • 99
  • 8

1 Answers1

2

If you put this into <head>, it will execute before #clickme exists in the DOM.

Solution is to wrap your code in a DOMContentLoaded listener:

document.addEventListener("DOMContentLoaded", function() {
  document.getElementById('clickme').addEventListener('click', hello);
});
Xan
  • 74,770
  • 16
  • 179
  • 206