javascript - Is the addEventListener method part of the document object? -
i'm not sure addeventlistener comes assume part of document object. if so, code document.getelementbyid('displaytodosbutton').addeventlistener
work same var displaytodosbutton = document.getelementbyid('displaytodosbutton');
?
var displaytodosbutton = document.getelementbyid('displaytodosbutton'); displaytodosbutton.addeventlistener('click',function(){ todolist.displaytodos(); });
it can object supports events: "the event target may element in document, document itself, window, or other object supports events (such xmlhttprequest)."
see https://developer.mozilla.org/en-us/docs/web/api/eventtarget/addeventlistener
document.getelementbyid('displaytodosbutton').addelementlistener
not work, because method's called addeventlistener
. other that, you're free save reference element in variable or directly use when returned .getelementbyid()
. result won't different.
Comments
Post a Comment