[Solved]Element.onclick = function()

Hello,
I wrote an addon pianomoz, https://addons.mozilla.org/en-US/firefox/addon/pianomoz/ so that artists can create their own musical instrument.
The music notes work very well on the keyboard, but there are often misfires using mouse click.
Does anyone know why?
I use for keybord :
window.addEventListener(“keydown”, function (event) {
if (event.defaultPrevented) {
return; // Should do nothing if the key event was already consumed.
}
and I use for mouse :
document.addEventListener(‘DOMContentLoaded’, function() {
var b1v = document.getElementById(‘b1v’);
b1v.onclick = function() {
toucheblanche1Press();
};

regards

To start with:
Assigning to the ‘onload’ property of DOM nodes which you do not own is unacceptable.
To prevent vulnerabilities, event handlers (like ‘onclick’ and ‘onhover’) should always be defined using addEventListener.

It is better to use ‘addEventListener’.

It should be
document.getElementById(‘b1v’).addEventListener(“click”, function() {
toucheblanche1Press();
});

Thank you very much for the reply.
I had written in the first versions “addEventListener”, but all the first click did not work, and the default often appeared after the first clik.
Can you tell me what form of writing to use with addEventListener, for all click to work?
it was :
function load() {
var cel1 = document.getElementById(“b1v”);
cel1.addEventListener(“click”, toucheblanche1Press, false);

}
document.addEventListener(“DOMContentLoaded”, function(event) {
load();
}

regards

Hello
Thank you very much for the reply. I test and correct quickly.

In theory you don’t have any error. Can you show all your code ?

How did you solve it?

Hello,
I would said, I would check before tomorrow and delete the onclick
The proposed addon codes are here
https://addons.mozilla.org/en-US/firefox/addon/pianomoz/
And I also placed under github


regards

Yes, it is solved, thank you very much.
In detail, I had a major error in the css code. I had set a too large displacement value in ‘: active.’ This error moved the object before the sound was played, so the click did not sound.
The fact of correcting the code js, allowed me to discover the error in the code css.
cordially