title: How to target an option in a select where option's ID changes dynamically using jQuery
body: <p>Using a CMS, I have created an event page, we can call it the Blueprint as it will be replicated to create child events, and any changes I make in the Blueprint can be pushed down to all child events.</p>
  
  <p>In my Blueprint, I have a survey where a drop down question asks the user to select their division.</p>
  
  <p>Based on which division is selected, the next question filters the list of regions available to that division. </p>
  
  <p>I'm trying to target an <code>&lt;option&gt;&lt;/option&gt;</code> element where the <code>id</code> is assigned by the system but the <code>id</code> is different for each replicated event.</p>
  
  <pre><code>  function showHideTEAM(selectedValue){
      if (selectedValue != "NORTH" &amp;&amp; selectedValue != "NORD" &amp;&amp; selectedValue != "TEAM CANADA") {
        $("#1684_53515_8_169135 &gt; option").each(function() {
          if($(this).val() == "TEAM CANADA") {
            $(this).remove();
          }
        });
      }
      if (selectedValue == "TEAM CANADA") {
        $("#1684_53515_8_169135 &gt; option").each(function() {
          if($(this).val() != "TEAM CANADA") {
            $(this).remove();
          }
        });
      } 
    }
    if ($("#1684_53515_7_169134").length &gt; 0) {
      $("#1684_53515_7_169134").on("change", function(event) {showHideMELLON($(this).val());});
    }
  </code></pre>
  
  <p>What is intended to happen is </p>
  
  <p>if user selects North (if they're on the English) or Nord (if on French) in the <code>id="1684_53515_7_169134"</code> the next question's filtered drop down (<code>id="1684_53515_8_169135"</code>) includes TEAM CANADA to the list. So far...this seems to work, despite replication and <code>id</code> changing and I'm not sure why.</p>
  
  <p>What isn't working is if in <code>id="1684_53515_7_169134"</code> you select TEAM CANADA the next question <code>id="1684_53515_8_169135"</code> should strip all options and only have TEAM CANADA as an option.</p>
  
  <p>I know it doesn't make sense to have TEAM CANADA there twice but its required.</p>
  
  <p>Some additional info, all event pages share a page-wrapper but the event pages are separate from each other. The registration flow (where this survey appears) is also separate between event pages. So why the system generates a new id number per event for the same fields across each event I don't know.</p>
  
  <p>ex:</p>
  
  <p>BLUEPRINT:</p>
  
  <pre><code>&lt;div class="form-content"&gt;
      &lt;span class="survey-question-number-container"&gt;
          &lt;span class="field-required"&gt;&lt;/span&gt;
          &lt;span class="field-number survey-question-number"&gt;
              4.
          &lt;/span&gt;
      &lt;/span&gt;
      &lt;span class="input-container"&gt;
          &lt;label for="1684_53515_7_169134"&gt;
              &lt;span class="aural-only"&gt;Field Is Required&lt;/span&gt;
              &lt;span class="input-label"&gt;Select Division&lt;/span&gt;
          &lt;/label&gt;
          &lt;span class="ungrouped"&gt;
              &lt;select name="1684_53515_7_169134" id="1684_53515_7_169134" onchange="choiceSelected('1684_53515_7_169134', this.selectedIndex);"&gt;
                  &lt;option value="NOREPLY"&gt;Please select response&lt;/option&gt;
                  &lt;option value="NORTH"&gt;NORTH&lt;/option&gt;
                  &lt;option value="EAST"&gt;EAST&lt;/option&gt;
                  &lt;option value="WEST"&gt;WEST&lt;/option&gt;
                  &lt;option value="SOUTH"&gt;SOUTH&lt;/option&gt;
                  &lt;option value="TEAM CANADA"&gt;TEAM CANADA&lt;/option&gt;
              &lt;/select&gt;
          &lt;/span&gt;
      &lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and then when you select an option, for example, NORTH you get the following list, with Team Canada.</p>
  
  <pre><code>&lt;div class="form-content"&gt;
      &lt;span class="survey-question-number-container"&gt;
          &lt;span class="field-required"&gt;&lt;/span&gt;
          &lt;span class="field-number survey-question-number"&gt;
              5.
          &lt;/span&gt;
      &lt;/span&gt;
      &lt;span class="input-container"&gt;
          &lt;label for="1684_53515_8_169135"&gt;
              &lt;span class="aural-only"&gt;Field Is Required&lt;/span&gt;
              &lt;span class="input-label"&gt;Select Team&lt;/span&gt;
          &lt;/label&gt;
          &lt;span class="ungrouped"&gt;
              &lt;select name="1684_53515_8_169135" id="1684_53515_8_169135" onchange="choiceSelected('1684_53515_8_169135', this.selectedIndex);"&gt;
                  &lt;option value="NOREPLY"&gt;&lt;/option&gt;
                  &lt;option value="FRIENDS AND FAMILY"&gt;FRIENDS AND FAMILY&lt;/option&gt;
                  &lt;option value="THE RETIREES"&gt;THE RETIREES&lt;/option&gt;
                  &lt;option value="ADMINISTRATION &amp;amp; ADMINISTERED"&gt;ADMINISTRATION &amp;amp; ADMINISTERED&lt;/option&gt;
                  &lt;option value="ADMINISTRATION - OTHER"&gt;ADMINISTRATION - OTHER&lt;/option&gt;
                  &lt;option value="CORPORATE DEVELOPMENT GROUP"&gt;CORPORATE DEVELOPMENT GROUP&lt;/option&gt;
                  &lt;option value="CORPORATE SECRETARY"&gt;CORPORATE SECRETARY&lt;/option&gt;
                  &lt;option value="GLOBAL REG AFF &amp;amp; RISK CONTROLS"&gt;GLOBAL REG AFF &amp;amp; RISK CONTROLS&lt;/option&gt;
                  [..another 10 options..]
                  &lt;option value="TEAM CANADA"&gt;TEAM CANADA&lt;/option&gt;
              &lt;/select&gt;
          &lt;/span&gt;
      &lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>If you were to select TEAM CANADA in the division, what happens is only TEAM CANADA is selectable in the Team List, and all other options get removed.</p>
  
  <pre><code>&lt;div class="form-content"&gt;
      &lt;span class="survey-question-number-container"&gt;
          &lt;span class="field-required"&gt;&lt;/span&gt;
          &lt;span class="field-number survey-question-number"&gt;
              5.
          &lt;/span&gt;
      &lt;/span&gt;
      &lt;span class="input-container"&gt;
          &lt;label for="1684_53515_8_169135"&gt;
              &lt;span class="aural-only"&gt;Field Is Required&lt;/span&gt;
              &lt;span class="input-label"&gt;Select Team&lt;/span&gt;
          &lt;/label&gt;
          &lt;span class="ungrouped"&gt;
              &lt;select name="1684_53515_8_169135" id="1684_53515_8_169135" onchange="choiceSelected('1684_53515_8_169135', this.selectedIndex);"&gt;
                  &lt;option value="NOREPLY"&gt;&lt;/option&gt;
                  &lt;option value="TEAM CANADA"&gt;TEAM CANADA&lt;/option&gt;
              &lt;/select&gt;
          &lt;/span&gt;
      &lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>CHILD EVENT:</p>
  
  <pre><code>&lt;div class="form-content"&gt;
      &lt;span class="survey-question-number-container"&gt;
          &lt;span class="field-required"&gt;&lt;/span&gt;
          &lt;span class="field-number survey-question-number"&gt;
              4.
          &lt;/span&gt;
      &lt;/span&gt;
      &lt;span class="input-container"&gt;
          &lt;label for="1684_55117_7_170272"&gt;
              &lt;span class="aural-only"&gt;Field Is Required&lt;/span&gt;
              &lt;span class="input-label"&gt;Select Division&lt;/span&gt;
          &lt;/label&gt;
          &lt;span class="ungrouped"&gt;
              &lt;select name="1684_55117_7_170272" id="1684_55117_7_170272" onchange="choiceSelected('1684_55117_7_170272', this.selectedIndex);"&gt;
                  &lt;option value="NOREPLY"&gt;Please select response&lt;/option&gt;
                  &lt;option value="NORTH"&gt;NORTH&lt;/option&gt;
                  &lt;option value="EAST"&gt;EAST&lt;/option&gt;
                  &lt;option value="WEST"&gt;WEST&lt;/option&gt;
                  &lt;option value="SOUTH"&gt;SOUTH&lt;/option&gt;
                  &lt;option value="TEAM CANADA"&gt;TEAM CANADA&lt;/option&gt;
              &lt;/select&gt;
          &lt;/span&gt;
      &lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>notice the <code>id</code>'s have changed, so now when you select TEAM CANADA you <strong>SHOULD</strong> ONLY have TEAM CANADA in this list but it doesn't work. It shows the full list (at the end of this question).</p>
  
  <pre><code>&lt;div class="form-content"&gt;
      &lt;span class="survey-question-number-container"&gt;
          &lt;span class="field-required"&gt;&lt;/span&gt;
          &lt;span class="field-number survey-question-number"&gt;
              5.
          &lt;/span&gt;
      &lt;/span&gt;
      &lt;span class="input-container"&gt;
          &lt;label for="1684_55117_8_170273"&gt;
              &lt;span class="aural-only"&gt;Field Is Required&lt;/span&gt;
              &lt;span class="input-label"&gt;Select Team&lt;/span&gt;
          &lt;/label&gt;
          &lt;span class="ungrouped"&gt;
              &lt;select name="1684_55117_8_170273" id="1684_55117_8_170273" onchange="choiceSelected('1684_55117_8_170273', this.selectedIndex);"&gt;
                  &lt;option value="NOREPLY"&gt;&lt;/option&gt;
                  &lt;option value="TEAM CANADA"&gt;TEAM CANADA&lt;/option&gt;
              &lt;/select&gt;
          &lt;/span&gt;
      &lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the full list of options that change based on what is selected in the Division dropdown:</p>
  
  <pre><code>        &lt;option value="NOREPLY"&gt;&lt;/option&gt;
      &lt;option value="FRIENDS AND FAMILY"&gt;FRIENDS AND FAMILY&lt;/option&gt;
      &lt;option value="THE RETIREES"&gt;THE RETIREES&lt;/option&gt;
      &lt;option value="ADMINISTRATION &amp;amp; ADMINISTERED"&gt;ADMINISTRATION &amp;amp; ADMINISTERED&lt;/option&gt;
      &lt;option value="ADMINISTRATION - OTHER"&gt;ADMINISTRATION - OTHER&lt;/option&gt;
      &lt;option value="CORPORATE DEVELOPMENT GROUP"&gt;CORPORATE DEVELOPMENT GROUP&lt;/option&gt;
      &lt;option value="CORPORATE SECRETARY"&gt;CORPORATE SECRETARY&lt;/option&gt;
      &lt;option value="GLOBAL REG AFF &amp;amp; RISK CONTROLS"&gt;GLOBAL REG AFF &amp;amp; RISK CONTROLS&lt;/option&gt;
      &lt;option value="INFRASTRUCTURE-OTHER"&gt;INFRASTRUCTURE-OTHER&lt;/option&gt;
      &lt;option value="INTERNAL AUDIT"&gt;INTERNAL AUDIT&lt;/option&gt;
      &lt;option value="LEGAL"&gt;LEGAL&lt;/option&gt;
      &lt;option value="TOTAL ADMINISTERED"&gt;TOTAL ADMINISTERED&lt;/option&gt;
      &lt;option value="CAPITAL MARKETS"&gt;CAPITAL MARKETS&lt;/option&gt;
      &lt;option value="CAO"&gt;CAO&lt;/option&gt;
      &lt;option value="CORPORATE BANKING"&gt;CORPORATE BANKING&lt;/option&gt;
      &lt;option value="ECONOMICS"&gt;ECONOMICS&lt;/option&gt;
      &lt;option value="GLOBAL INVESTMENT BANKING"&gt;GLOBAL INVESTMENT BANKING&lt;/option&gt;
      &lt;option value="GLOBAL MARKETS"&gt;GLOBAL MARKETS&lt;/option&gt;
      &lt;option value="LEADERSHIP"&gt;LEADERSHIP&lt;/option&gt;
      &lt;option value="OTHER"&gt;OTHER&lt;/option&gt;
      &lt;option value="CLIENT CONNECTIVITY AND INNOVATION"&gt;&lt;/option&gt;
      &lt;option value="CC&amp;amp;I OTHER"&gt;CC&amp;amp;I OTHER&lt;/option&gt;
      &lt;option value="CLIENT ACCOUNT MANAGEMENT"&gt;CLIENT ACCOUNT MANAGEMENT&lt;/option&gt;
      &lt;option value="CLIENT CONTACT CENTRES"&gt;CLIENT CONTACT CENTRES&lt;/option&gt;
      &lt;option value="CLIENT EXPERIENCE"&gt;CLIENT EXPERIENCE&lt;/option&gt;
      &lt;option value="CONTACT CENTRES, CENTRES OF EXPERTISE"&gt;CONTACT CENTRES, CENTRES OF EXPERTISE&lt;/option&gt;
      &lt;option value="DIRECT BANKING, INNOVATION AND ANALYTICS"&gt;DIRECT BANKING, INNOVATION AND ANALYTICS&lt;/option&gt;
      &lt;option value="ENTERPRISE PROCESS MANAGEMENT"&gt;ENTERPRISE PROCESS MANAGEMENT&lt;/option&gt;
      &lt;option value="RETAIL TRANSACTION FRAUD"&gt;RETAIL TRANSACTION FRAUD&lt;/option&gt;
      &lt;option value="COMMERCIAL BANKING AND WEALTH MANAGEMENT"&gt;COMMERCIAL BANKING AND WEALTH MANAGEMENT&lt;/option&gt;
      &lt;option value="BUSINESS EFFECTIVENESS AND CLIENT SERVICES"&gt;BUSINESS EFFECTIVENESS AND CLIENT SERVICES&lt;/option&gt;
      &lt;option value="ASSET MANAGEMENT"&gt;ASSET MANAGEMENT&lt;/option&gt;
      &lt;option value="TEAM CANADA"&gt;TEAM CANADA&lt;/option&gt;
      &lt;option value="ENGINEERING"&gt;ENGINEERING&lt;/option&gt;
      &lt;option value="COMMERCIAL BANKING"&gt;COMMERCIAL BANKING&lt;/option&gt;
      &lt;option value="COMMERCIAL PRODUCTS, FINANCIAL PLANNING AND ADVICE, ADVISOR SERVICES"&gt;COMMERCIAL PRODUCTS, FINANCIAL PLANNING AND ADVICE, ADVISOR SERVICES&lt;/option&gt;
      &lt;option value="OTHER"&gt;OTHER&lt;/option&gt;
      &lt;option value="PRIVATE WEALTH MANAGEMENT"&gt;PRIVATE WEALTH MANAGEMENT&lt;/option&gt;
      &lt;option value="WEALTH MANAGEMENT HEAD OFFICE"&gt;WEALTH MANAGEMENT HEAD OFFICE&lt;/option&gt;
      &lt;option value="HUMAN RESOURCES AND COMMUNICATIONS"&gt;HUMAN RESOURCES AND COMMUNICATIONS&lt;/option&gt;
      &lt;option value="COMMUNICATIONS &amp;amp; PUBLIC AFFAIRS"&gt;COMMUNICATIONS &amp;amp; PUBLIC AFFAIRS&lt;/option&gt;
      &lt;option value="HUMAN RESOURCES"&gt;HUMAN RESOURCES&lt;/option&gt;
      &lt;option value="PURPOSE, BRAND AND MARKETING"&gt;PURPOSE, BRAND AND MARKETING&lt;/option&gt;
      &lt;option value="PERSONAL AND SMALL BUSINESS BANKING, CANADA"&gt;PERSONAL AND SMALL BUSINESS BANKING, CANADA&lt;/option&gt;
      &lt;option value="BANKING CENTRES"&gt;BANKING CENTRES&lt;/option&gt;
      &lt;option value="BUSINESS BANKING"&gt;BUSINESS BANKING&lt;/option&gt;
      &lt;option value="DIRECT INVESTING AND ADVICE"&gt;DIRECT INVESTING AND ADVICE&lt;/option&gt;
      &lt;option value="MOBILE ADVICE"&gt;MOBILE ADVICE&lt;/option&gt;
      &lt;option value="DELIVERY AND OPERATIONAL EFFECTIVENESS"&gt;DELIVERY AND OPERATIONAL EFFECTIVENESS&lt;/option&gt;
      &lt;option value="PERSONAL BANKING PRODUCTS"&gt;PERSONAL BANKING PRODUCTS&lt;/option&gt;
      &lt;option value="PROJECTS"&gt;PROJECTS&lt;/option&gt;
      &lt;option value="SEVP DIRECTS"&gt;SEVP DIRECTS&lt;/option&gt;
      &lt;option value="STRATEGY AND TRANSFORMATION"&gt;STRATEGY AND TRANSFORMATION&lt;/option&gt;
      &lt;option value="TECHNOLOGY &amp;amp; OPERATIONS"&gt;TECHNOLOGY &amp;amp; OPERATIONS&lt;/option&gt;
      &lt;option value="APPLICATION DELIVERY PROJECTS"&gt;APPLICATION DELIVERY PROJECTS&lt;/option&gt;
      &lt;option value="CAPITAL MARKETS/WEALTH MGMT OP"&gt;CAPITAL MARKETS/WEALTH MGMT OP&lt;/option&gt;
      &lt;option value="CORPORATE SERVICES"&gt;CORPORATE SERVICES&lt;/option&gt;
      &lt;option value="ENTERPRISE PAYMENTS"&gt;ENTERPRISE PAYMENTS&lt;/option&gt;
      &lt;option value="ENTERPRISE PRGMS &amp;amp; DELIVERY EX"&gt;ENTERPRISE PRGMS &amp;amp; DELIVERY EX&lt;/option&gt;
      &lt;option value="ENTERPRISE SECURITY &amp;amp; RISK SER"&gt;ENTERPRISE SECURITY &amp;amp; RISK SER&lt;/option&gt;
      &lt;option value="OTHER"&gt;OTHER&lt;/option&gt;
      &lt;option value="RETAIL OPERATIONS &amp;amp; INTRIA"&gt;RETAIL OPERATIONS &amp;amp; INTRIA&lt;/option&gt;
      &lt;option value="RO&amp;amp;I PROJECTS &amp;amp; BASE OPERATION"&gt;RO&amp;amp;I PROJECTS &amp;amp; BASE OPERATION&lt;/option&gt;
      &lt;option value="T&amp;amp;O DIRECTS"&gt;T&amp;amp;O DIRECTS&lt;/option&gt;
      &lt;option value="TECHNOLOGY"&gt;TECHNOLOGY&lt;/option&gt;
      &lt;option value="TOTAL FINANCE"&gt;TOTAL FINANCE&lt;/option&gt;
      &lt;option value="CFO GROUP"&gt;CFO GROUP&lt;/option&gt;
      &lt;option value="FINANCE SHARED SERVICES"&gt;FINANCE SHARED SERVICES&lt;/option&gt;
      &lt;option value="OTHER"&gt;OTHER&lt;/option&gt;
      &lt;option value="TAXATION"&gt;TAXATION&lt;/option&gt;
      &lt;option value="TREASURY"&gt;TREASURY&lt;/option&gt;
      &lt;option value="TOTAL RISK MANAGEMENT"&gt;TOTAL RISK MANAGEMENT&lt;/option&gt;
      &lt;option value="ANTI-MONEY LAUNDERING"&gt;ANTI-MONEY LAUNDERING&lt;/option&gt;
      &lt;option value="CAPITAL MARKETS"&gt;CAPITAL MARKETS&lt;/option&gt;
      &lt;option value="GLOBAL COMPLIANCE GROUP"&gt;GLOBAL COMPLIANCE GROUP&lt;/option&gt;
      &lt;option value="GLOBAL CREDIT RISK MANAGEMENT"&gt;GLOBAL CREDIT RISK MANAGEMENT&lt;/option&gt;
      &lt;option value="GLOBAL OPERATIONAL RM"&gt;GLOBAL OPERATIONAL RM&lt;/option&gt;
      &lt;option value="RISK ANALYTICS, REPORTING AND CREDIT DECISIONING"&gt;RISK ANALYTICS, REPORTING AND CREDIT DECISIONING&lt;/option&gt;
      &lt;option value="RISK MANAGEMENT - OTHER"&gt;RISK MANAGEMENT - OTHER&lt;/option&gt;
  </code></pre>
  
  <p>So is there a way to make this work dynamically so I don't have to do an if statement for 58 <code>id</code>'s?</p>
  
  <p>Thank you for your help!</p>