0

Please note that I want to use JQuery for this. This question How to trigger a click on a link using jQuery provided a solution for when only one anchor exists inside the list

However I have more than one list item and more than one anchor.

<ul id="navigation_list">
  <li id="sub_menu1_tab" style="">
    <span class="decorator"></span>
    <a id="policies" href="#admin/menu1_list" class="admin-submenu-item"></a>
  </li>
  <li id="sub_menu2_tab" style="">
    <span class="decorator"></span>
    <a id="rules" href="#admin/menu2_list" class="admin-submenu-item"></a>
  </li>
  <li id="sub_menu3_tab" style="">
    <span class="decorator"></span>
    <a id="reports" href="#admin/menu3_list" class="admin-submenu-item"></a>
  </li>
</ul>

How do I trigger a click on only one of the anchors? For example I want to trigger the second list item anchor. I have tried the following without success

$("#sub_menu2_tab a").trigger('click');

and

$("#navigation_list #sub_menu2_tab a").trigger('click');
Community
  • 1
  • 1
snowleopard
  • 781
  • 3
  • 13
  • 36
  • are you sure the issue is with the .trigger()? it works in [this fiddle](http://jsfiddle.net/epc3paop/) – ltotally Mar 12 '15 at 18:39

1 Answers1

1

just try

$("#sub_menu2_tab a").click();
levi
  • 22,001
  • 7
  • 73
  • 74
  • I actually had tried the .click() version also. This didn't work for me either. I am suspecting that either this has to do with the anchor being inside a li that's inside a ul or some deeper issue with my code I am missing. Thanks though. – snowleopard Mar 12 '15 at 17:31
  • @snowleopard what do u get when call `$("#sub_menu2_tab a")` ? can you inspect your browser console? – levi Mar 12 '15 at 18:16