XF 2.1 Trigger to open all spoilers

HappyWorld

Well-known member
How to open all spoilers in page using JS?
I've tried this but it doesn't work.

Code:
jQuery(document).ready(function(){
    jQuery('.bbCodeSpoiler-button').click();
});

I've tried similar code in XF 1 and it worked.
 
I've just tested code similar to that in the browser console and it works as expected.

You're probably triggering that JS before jQuery is even loaded. That doesn't get loaded until (effectively) at the </body> tag.

You can use <xf:js> tags to insert inline JS at the end of the body (rather than normal script tags).

Saying that, editing the spoiler template to expand them is probably easier (thought also somewhat defeating the point of a spoiler system). Add the is-active class to the bbCodeSpoiler-content element.
 
Back
Top Bottom