0

I have a jquery accordion style menu that I'd like to add some shortcut links to across the top. When one of these shortcuts is clicked, it should have the same effect as if the user clicked the corresponding a tag that serves as that panel's header...

Here's some code...

<div>
    Application Shortcuts > <a href="" 
    onclick="simulateAclick("generalSettings")>Open General Settings</a>
</div>


<ul class="menu collapsible">
  <li class='header'><a href='#' id="generalSettings">General Settings</a>
      <ul class='acitem'>...stuff goes here...

In the example above, clicking on "Open General Settings" toggles the "acitem" UL's child elements visible. I'd just like to simulate a click on that element, from a link at the top of my app...

3 Answers 3

4

Use this:

$('#generalSettings').click();

The # prefix means to look for an element with the ID that follows.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use the click function on all jQuery objects to simulate a click event.

This fires the event as if it were done by the user. Except obvious event properties such as clientX and clientY, etc won't be accurate and/or available.

Comments

1

There's an official function for this ;)

$('#generalSettings').trigger('click');

Comments

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.