I'm trying to understand why this code below executes my function as soon as the document is loaded:
var list = document.getElementsByTagName('li');
function yep() {
window.alert('yep');
}
list[0].onclick = yep();
list[0].onclick = yep;
()
The parenthesis ()
execute function immediately. On your second line you are assigning the value of list[0].onclick
to the function name but not executing it.