Search code examples
javascriptjqueryhtmlqualtrics

jquery based on a condition


I am working on a survey platform. By default I have a footer that shows up in all survey pages. I need the footer to display only on the first display page. In order to do this I am attaching this jQuery to all pages where I want the footer hidden:

jQuery("#Footer").hide();

The issue I am having now is that based on a link condition, the first page of the survey can be page1 or page2. This means. I have 2 scenarios:

  1. I access the survey using link1. This should start on pag1, pag2, pag3. The footer is displayed only on pag1 and is hidden by jQuery on the subsequent pages.
  2. I access the survey using link2. This should start display pag2 first. The footer is not displayed and is hidden by the jQuery I applied.

Any ideas?


Solution

  • Add this script to pag1 and pag2.
    I assume your URL to be something like : link1/**/**/pag1 or link2/**/**/pag2

    var pageURL = window.location.href;
    
    if((pageURL.includes("link1") && pageURL.includes("pag1")) || 
       (pageURL.includes("link2") && pageURL.includes("pag2")))
    {
        jQuery("#Footer").show();
    }
    else
    {
        jQuery("#Footer").hide();
    }