How to cause last accordion in mobile friendly matrix to auto close upon answer selection? | Experience Community
Skip to main content
Solved

How to cause last accordion in mobile friendly matrix to auto close upon answer selection?

  • Sep 17, 2021 11:00 PM UTC
  • 2 replies
  • 296 views

I am working on a mobile friendly accordion style matrix question and the UI for the first 3 statement options auto collapses the accordion to show the next statement. How do I achieve the same effect for the 4th and final statement before the user would continue to the next question?
image.png

Best answer by ChiragK

Hi Jared, Try adding this JavaScript code in that question.
Qualtrics.SurveyEngine.addOnReady(function () {
    var $this = jQuery(this.questionContainer);
    var isMobile = jQuery(".QuestionBody", $this).is(".mobile");
    jQuery(".ChoiceRow input[id][name]", $this).on("change", function () {
        if (isMobile && jQuery(this).closest(".ChoiceRow").nextAll(".ChoiceRow").length === 0) {
            jQuery(this).closest(".ChoiceRow").find("th[id]").click();
        }
    });
});

View original

2 replies

Forum|alt.badge.img+8
  • Level 2 ●●
  • Answer
  • Sep 22, 2021 12:00 PM UTC

Hi Jared, Try adding this JavaScript code in that question.
Qualtrics.SurveyEngine.addOnReady(function () {
    var $this = jQuery(this.questionContainer);
    var isMobile = jQuery(".QuestionBody", $this).is(".mobile");
    jQuery(".ChoiceRow input[id][name]", $this).on("change", function () {
        if (isMobile && jQuery(this).closest(".ChoiceRow").nextAll(".ChoiceRow").length === 0) {
            jQuery(this).closest(".ChoiceRow").find("th[id]").click();
        }
    });
});


Thank you! This worked like a charm!