Code not working

I have used the following code to open accordions on pages, New York gun laws is a page it works on.

/opens closes accordions/
jQuery(function($) {
$(’.acc-btn-toggle’).on(‘click touchend’, function(e) {
e.preventDefault();
$(’.x-acc-header, .x-accordion-toggle’).trigger(‘click’);
})
})

However when I use it on posts it will not work. This is the post I am trying to get it to work on. Do I need to modify the code for posts?

Hi There,

There is a syntax error in your custom JS:

*/opens closes accordions*/
jQuery(function($) {
  $('.acc-btn-toggle').on('click touchend', function(e) {
     e.preventDefault();
    $('.x-acc-header, .x-accordion-toggle').trigger('click');
  })
})

It should be like this:

/* opens closes accordions */
jQuery(function($) {
  $('.acc-btn-toggle').on('click touchend', function(e) {
     e.preventDefault();
    $('.x-acc-header, .x-accordion-toggle').trigger('click');
  })
});

Regards!

Thanks yes that was definitely an error. Have corrected it but for some reason it will open the accordions but not close them, so not sure why that is

Hey @waynepatt58,

The code you posted isn’t specific to page or post. Your setup might just be different. There’s also no accordion element in your post.

Regretfully, fixing the code even if you got it from here in the forum would be veering into custom development since this is not a native feature of the theme. Custom codes here were only meant to be a guide or starting point. To continue with the custom JS development, you will need to consult with a third party developer. Or, you can learn jQuery to fix the code for your posts.

Thank you for understanding.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.