+ 1
4 odpowiedzi
+ 4
The JavaScript error is from how you tried to access the document to link your click event handler before the document's content fully loaded.
Here is a fixed version of your JavaScript:
document.addEventListener('DOMContentLoaded', function() {
var left = document.getElementById('left');
left.onclick = function (){
alert ("test")
}
});
+ 1
Ferenando my answer wasn't best as I didn't provide an explanation unlike Josh Greig
0
I think it's about lef. Onclick, if you want to make it simple, better delete that before the function, put a name to the function and use it as an onclick attribute within the tag and function name., it's easier like this, or instead you can use the getElement
0
Or try putting code inside following function
window.onload=function(){
}