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 ?

5th Sep 2020, 8:47 AM
Hima
Hima - avatar
7 odpowiedzi
+ 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 }
5th Sep 2020, 8:49 AM
Abhay
Abhay - avatar
+ 2
Hima add "this" instead of ele[0] this.removeEventListener('click',fun);
5th Sep 2020, 11:14 AM
Abhay
Abhay - avatar
+ 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; } }
5th Sep 2020, 12:04 PM
Abhay
Abhay - avatar
+ 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?
5th Sep 2020, 11:35 AM
Abhay
Abhay - avatar
0
Abhay I have made some changes in the code. How can I remove the eventlistener from the clicked buttons ?
5th Sep 2020, 10:46 AM
Hima
Hima - avatar
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"?
5th Sep 2020, 11:32 AM
Hima
Hima - avatar
0
Abhay only when both buttons are clicked consecutively with the same class "match"
5th Sep 2020, 11:40 AM
Hima
Hima - avatar