Jump to content

Triggering jQuery UI accordion element from elsewhere


Mad_Griffith

Recommended Posts

Hi, I want to trigger a jQuery UI accordion element from a separate link and the following works so far. The problem is that whenever any other element in the accordion is clicked, the accordion element I triggered from the link stays open. Why so?

<a onclick="jQuery('.ui-accordion-header:nth-of-type(3)').removeClass('ui-state-default ui-corner-all').addClass('ui-state-active ui-corner-top').attr({'aria-expanded': true, 'aria-selected': true}); jQuery('.ui-accordion-content:nth-of-type(3)').addClass('ui-accordion-content-active').css({'display' : 'block','overflow': 'hidden'}); jQuery('.ui-accordion-header:nth-of-type(3)')[0].scrollIntoView(true);" style="color: white; background-color: red; padding: 15px; font-size: 25px; text-transform: uppercase">Participate</a>
Edited by Mad_Griffith
Link to comment
Share on other sites

I've just found out that I could use this shorthand, but still would like to know what was missing in the code above...

<a onclick="jQuery('.ui-accordion').accordion({ active: 2 });jQuery('.ui-accordion-header:nth-of-type(3)')[0].scrollIntoView(true);" style="color: white; background-color: red; padding: 15px; font-size: 25px; text-transform: uppercase">Participate</a>
Edited by Mad_Griffith
Link to comment
Share on other sites

So jQuery similar to this which does the same thing wouldn't work for you?

            jQuery(function() {                jQuery('body').on('click', '.accordian_anchor_trigger', function() {                    jQuery('.ui-accordion').accordion({active: 2});                    jQuery('.ui-accordion-header:nth-of-type(3)')[0].scrollIntoView(true);                });            });
 .accordian_anchor_trigger {color: white; background-color: red; padding: 15px; font-size: 25px; text-transform: uppercase;}
<a class="accordian_anchor_trigger">Participate</a>
Edited by dsonesuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...