Button disappears on click #1454
-
Hi! I am trying to create a reaction time task using the html-button-response plugin. I have a series of image buttons, that appear on screen at the same time and I am trying to make it so that each button disappears from the screen when clicked and when all buttons are clicked and disappear then the trial ends. So far I only managed to make all of them disappear at the same time. Any ideas on how I can make this work? I'm adding here the code where I have the buttons: Here is the part that makes all buttons disappear, but I want only the clicked button to disappear and the other ones to remain: I would appreciate any help or ideas! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @afine1927, my approach to this would be to do two things each time a button is clicked (i.e. inside the click event handler):
The second bit of code you provided shows how to grab all of the button elements and loop over them. So to do the second step above, then inside the loop you'd just be checking if any of the buttons are disabled/hidden - something like this: // this goes inside your the click function for your buttons
// first disable/hide the button that was just clicked, then:
var all_clicked = true;
var btns = document.querySelectorAll('.jspsych-html-button-response-button button');
for(var i=0; i<btns.length; i++){
if (btns[i].getAttribute('disabled') == false) { // I'm not sure what this returns when the button isn't disabled... might need to change "false" to something else
all_clicked = false; // if any one button is still active, then we don't want to end the trial yet
}
}
if (all_clicked) { // if all buttons are disabled/clicked, then end the trial
end_trial();
} And if you want to hide the buttons rather than disable them, you would set their 'visibility' attribute to 'hidden'. |
Beta Was this translation helpful? Give feedback.
Hi @afine1927, my approach to this would be to do two things each time a button is clicked (i.e. inside the click event handler):
The second bit of code you provided shows how to grab all of the button elements and loop over them. So to do the second step above, then inside the loop you'd just be checking if any of the buttons are disabled/hidden - something like this: