0
[Solved]Why the error ?
addEventListener is not a function ? I couldn't see why the error ! https://code.sololearn.com/WfYjqvHkWsXF/?ref=app Edit: I have made some changes in the code. How can I remove the eventlistener from the clicked buttons ?
7 Réponses
+ 2
getElementsByClassName returns a node list of "elements" so you need to specify by indexing which element you are referring to like ele[0] ,also you need to put your js code inside window.onload function
window.onload=function(){
Js code
}
+ 2
Hima add "this" instead of ele[0]
this.removeEventListener('click',fun);
+ 2
Hima I think this does the work !!
function fun()
{
console.log("hello");
if(this.classList[1]=="match" & count==0){
count=1;
}
else if(this.classList[1]=="match" & count==1){
for(i of deck.children){
if(i.classList[1]=="match"){
i.removeEventListener('click',fun);
}
}
count=0;
}
else{
this.removeEventListener('click',fun);
count=0;
}
}
+ 1
So what you want to do? If one button with class match is clicked remove event listener from other button as well with same class?
0
Abhay I have made some changes in the code.
How can I remove the eventlistener from the clicked buttons ?
0
Abhay
Say , I'm checking for two buttons now.
How can I remove the eventlisteners from both the buttons when they have the same class "match"?
0
Abhay
only when both buttons are clicked consecutively with the same class "match"