I'm new to JavaScript and I'm trying to make a Chrome extension that prints a message whether it can access a button. This is my code:
chrome.browserAction.onClicked.addListener(function(tab) {
var button = document.getElementById("mybutton");
if(button == null){
alert("doesn't work");
}
else{
alert("works");
}
});
This shows 'doesn't work'. What am I doing wrong?
This is my html page:
<html>
<button id="mybutton">click me</button>
<script>
var greeting = "hello, ";
var button = document.getElementById("mybutton");
button.person_name = "Bob";
button.addEventListener("click", function() {
alert(greeting + button.person_name + ".");
}, false);
</script>
</html>