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');
1
  • are you sure the issue is with the .trigger()? it works in this fiddle Commented Mar 12, 2015 at 18:39

1 Answer 1

1

just try

$("#sub_menu2_tab a").click();
Sign up to request clarification or add additional context in comments.

2 Comments

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 what do u get when call $("#sub_menu2_tab a") ? can you inspect your browser console?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.