Ad

Open First Item In Accordion On Page Load

- 1 answer

Got a sidebar filter in my site that has accordion headers. I would like to be able to have the 1st item always open (/expanded) with an option to do the same with the 2nd one.

This is the js: (Its a script from a shopify app called Power Tools)

<script type="text/javascript">
  $(function(){
    $('.filter-menu h4').on('click', function(e){
        $(this).closest('.filter-group').not('.has_group_selected, .refine-header').toggleClass('expanded').find('ul,.filter-clear').toggle('fast');
        e.preventDefault();
    })
  });
</script>

Here's a link: https://www.zoobgear.com/collections/punching-bags

(trying to make the category item always open)

Any suggestions? maybe altering the script would do the trick...?

Thanks a ton for any advice!!!

Ad

Answer

If you have access to the accordion plugin then you can make modify it to expand any options on page load based on which plugin is used. In case you need any jQuery script to open the category menu in expanded form this can be done by using following code.

$('.filter-group-category').find('h4').trigger('click');   
Ad
source: stackoverflow.com
Ad