Closed mohamedrchalal closed 8 years ago
Would you mind copying some of your code here relative to your issue? Specifically are you trying to add an event listener to an array of multiple elements? If so, once the event listener has been added, if you try to console.log(this) on the callback function of your click event, it should display the clicked element
for(j=0;j<document.querySelectorAll('.answers').length;j++){
document.querySelectorAll('.answers')[j].addEventListener('click',nextQuestion);
console.log(document.querySelectorAll('.answers')[j])
if (document.querySelectorAll('.answers').innerHTML == deadpoolTrivia.correctAnswers[i]){
score = score +1;
}
}
Start off by breaking it up into some variables. document.querySelectorAll(".answers")
repeats 4 times. Do it once and save it to a variable.
hey guys, ok i figured some of this stuff out, becky showed me yesterday what to console.log to find out what button is being clicked, and i lost that info/for got it. Could you please remind me? i know it goes in my nextQuestion function but not sure what to put in console.log('')
If you console.log(this)
inside the callback function nextQuestion
, it should display the clicked element
NICK:
please take a look at what i have so far, I am not able to figure out how to select what the user has clicked on?