Linked Questions
274 questions linked to/from addEventListener vs onclick
10 votes
3 answers
22k views
What is the difference between window.onload() and document.addEventListener('load', ..)? [duplicate]
It seems to me that both events are fired when every resource and its dependent resources have finished loading. This rises some questions: Is there any difference between those events? Which event ...
10 votes
2 answers
22k views
Onclick vs addEventListener [duplicate]
I'm little confusing by using "onclick" "onmousedown" as a property of HTML elements. Such as: <button onclick="my_JS_function()"></button> or <div onmousedown="...
8 votes
2 answers
22k views
How to bind an event listener only once in pure JavaScript? [duplicate]
I already know the Jquery solution $('#myid').one('click', function(event) { ... }); But now I'm finding the Pure JavaScript way because I'm not using Jquery I have checked the once option but it ...
32 votes
0 answers
25k views
element.onload vs element.addEventListener("load",callbak,false) [duplicate]
Can someone please explain what the difference is between the following two ways to specifying onload callback functions in javascript? element.onload = callback AND element.addEventListener("load",...
-1 votes
6 answers
305 views
Control HTML DOM with Javascript without inserting calling functions in tags [duplicate]
Both codes below do the same thing, first using Vanilla JS and second using JQuery. JQuery code do not have to insert anything inside html tags, while JS have to insert the caller "onclick="myFunction(...
0 votes
1 answer
2k views
What is the difference between .onclick and .addEventListener("click", function())? [duplicate]
New to javascript and I find myself often trying one before realizing the other one is what I need, are they not doing the same thing?
0 votes
1 answer
2k views
window.onmesage vs window.addEventListener("message", onMessage); [duplicate]
I was wondering what is the difference between those two ways of listening a message. Here is my assumptions: window.onmesage = onMessage This assign a function to the onmessage attribute of the ...
0 votes
3 answers
1k views
Difference between using ID and onClick [duplicate]
I apologize if this post has been made before but I wasn't able to find it. Imagine we have <button class="sample-class" role="button" tabindex="0" id="onEvent">play</button> and then a ...
0 votes
2 answers
2k views
Multiple event listener on the same object not working [duplicate]
Is it possible to have two listener listening to the same event? I have an event listener listening for the oncanplay video event, and in some other class, in this example the test class, I have to ...
2 votes
1 answer
2k views
Event listener vs event handler [duplicate]
Can someone explain what is the proper way to make certain actions call functions in javascript? Should I use event handlers like onclick="callFunction();"? Or should I use an event listener? If yes, ...
2 votes
1 answer
991 views
Proper and most efficient way to add events in Javascript? [duplicate]
I am developing an app and speed is a concern. When attaching events to elements there are two ways that I know how to do it: element.addEventListener('click', function() { // code to execute ...
1 vote
1 answer
907 views
What is the difference between calling addEventListener() vs. adding the event + function into the HTML tag [duplicate]
What is the difference between using addEventListener() in your Javascript code like this example: Array.from(document.querySelectorAll('.element')).forEach(el => { el.addEventListener('ondrop',...
1 vote
2 answers
935 views
How to call/handle different event handlers for same event on same element? JavaScript [duplicate]
I'm curious here, I know that it's possible to attach multiple event handlers to same element if I use DOM Level 2 method called addEventListener(), so I'm wondering if we have this situation: ...
0 votes
1 answer
995 views
toggle class on click with javascript on 2 ways, which is correct? [duplicate]
Are any of these versions correct? I would like the icon to change after clicking the menu. in Javascript these are my beginnings and I don't know what is right const menu = document.querySelector('#...
2 votes
3 answers
188 views
Calling JS function is better or using click event [duplicate]
If I have below button : <button type="button" id="send_email" class="btn btn-primary" onclick="sendEmail();">Send</button> So, which is better calling JS function or using click event ...