I have the following function which has the required functionality. Is there any way that I can reduce the code but have the same functionality?
addClickEventListeners = () => {
let multipleChoiceQuestionButtons = document.querySelectorAll('[name="multiple_choice"]');
let trueFalseQuestionButtons = document.querySelectorAll('[name="true_false"]');
let multipleChoiceMultiAnswersQuestionButtons = document.querySelectorAll('[name="multi_answers"]');
if (multipleChoiceQuestionButtons.length > 0) {
multipleChoiceQuestionButtons.forEach((button) => {
button.addEventListener('click', someFunction, false);
});
} else if (trueFalseQuestionButtons.length > 0) {
trueFalseQuestionButtons.forEach((button) => {
button.addEventListener('click', someFunction, false);
});
} else if (multipleChoiceMultiAnswersQuestionButtons.length > 0) {
multipleChoiceMultiAnswersQuestionButtons.forEach((button) => {
button.addEventListener('click', someFunction, false);
});
}
};
someFunction
in all three cases? \$\endgroup\$