0

I have two sets of links with dynamic id's. The first set is hidden from view (display:none;). I need to make clicking on a link from the second set trigger a link click in the first set based on matching id's.

Here's my code:

HTML output

// Hidden from user
<div class="set1">
  <div class="alm-filter alm-filter--taxonomy" id="alm-filter-2">
    <ul>
      <li><a href="javascript:void(0);" class="alm-filter--link field-radio field-test10" id="radio-test10-2">Link 1</a></li>
      <li><a href="javascript:void(0);" class="alm-filter--link field-radio field-test11" id="radio-test11-2">Link 2</a></li>
    </ul>
  </div>
</div>

// Displayed to user
<div class="set2">
  <div class="alm-filter alm-filter--taxonomy" id="alm-filter-2">
    <ul>
      <li><a href="javascript:void(0);" class="alm-filter--link field-radio field-test10" id="radio-test10-2">Link 1</a></li>
      <li><a href="javascript:void(0);" class="alm-filter--link field-radio field-test11" id="radio-test11-2">Link 2</a></li>
    </ul> 
  </div>
</div>

My Jquery thus far:

$(document).on('click', '.industry-filter-terms #alm-filter-2 .alm-filter--radio .alm-filter--link', function(event) { 
  event.preventDefault();
  var set2LinkId = $(this).attr('id');
  var set1LinkId = $( '.expertise-filter-terms #alm-filter-2 ' + myClass );
  $( this ).trigger( 'click' );
});

So basically what I'm trying to do is on click of set link, get it's id, find the link in the first set with the matching id and click it. So far I can't even get var set1LinkId to come back with anything but an empty array. I'm not very experienced with sequencing events and I've looked everywhere but can't figure what to do... Help?

Furio
  • 11
  • 5
  • It is invalid to have the same ID on two different elements in the same document. – Heretic Monkey Mar 30 '18 at 16:21
  • 1
    @MikeMcCaughan You're totally right and I'm really embarrassed I somehow overlooked that I was duplicating IDs. I think I'm so frustrated with trying to force a different layout on mobile that will work with my filter set up I didn't even notice I was loading them. Thanks for posting the similar question, which does address what I'm trying to, but I really don't want to do something that's invalid in the first place. – Furio Mar 30 '18 at 16:55
  • @MikeMcCaughan What do you when you realize your question sucks? Do I leave an answer saying it's just not a good idea to proceed with the scenario or do I remove it altogether somehow? – Furio Mar 30 '18 at 16:57
  • When I flagged it as a duplicate, it should have asked if you agreed. If so, you can just agree and it will be closed as a duplicate. Otherwise, since there are no answers (and no votes) it's probably safe to just delete it. – Heretic Monkey Mar 30 '18 at 17:01
  • @MikeMcCaughan Awesome, thanks! – Furio Mar 30 '18 at 22:52

0 Answers0