How can I attach an event to a button on the popup of a chrome extension? I read this https://developer.chrome.com/extensions/contentSecurityPolicy#JSExecution and still can't make it work; the script just executes the "awesome" functions once and then my button does nothing.
PD: I'm a beginner at both Javascript and Chrome extensions, so I'm not sure where exactly am I doing something wrong. I'll add both tags, if that's ok.
Edit: I add the code for my extension, although is almost the same as in the example in the developer.chrome link.
popup.html
<!doctype html> <html> <head> <title>Getting Started Extension's Popup</title> <script src="creatediv.js"></script> </head> <body> <button id="aaaa">something</button> </body> </html> creatediv.js
document.addEventListener('DOMContentLoaded', function () { document.getElementById('aaaa').addEventListener('click', loadDiv()); }); function loadDiv(){ var myDiv = document.createElement("div"); document.documentElement.appendChild(myDiv); myDiv.id = "mydiv"; myDiv.innerHTML = "asdf"; alert(123); return false; }; When I click on the extension icon the loadDiv function gets executed: i get a window alert with 123 on it and then a div with "asdf" is appeneded to popup.html. The button "something" does nothing.