on this page: https://cesmeglise.org/recherche-dans-la-bible/)
I try to initiate an event after another script:
My script try to 'alert button' on click button
document.addEventListener('click', function (e) {
if(document.querySelectorAll("button")===e.target) {
alert('button');
}
}, false);
exemple on the page button called "Verset Aléatoire" nothing happens
with your help i try this
var i,dots;
dots = document.getElementsByClassName('button');
document.addEventListener('click', function (e) {
for (i=0; i<dots.length; i ){
if(document.querySelectorAll("button")[i]===e.target) {
alert('button');
}
}
}, false);
nothings happens
CodePudding user response:
You're not selecting the exact element what you need is to use an id for your button and then use a selector like document.getElementById('id')
CodePudding user response:
As explained in the docs, querySelectorAll returns a NodeList so you cannot check for equivalence with e.target. If you must use this function you could try iterating over the NodeList instead.