• Resolved sdonnet

    (@sdonnet)


    Hi,

    I work with Ultimate Shortcode for a while, but it is the first time I am facing a problem which I can not solve. May be it is very simple, but…
    I have several su_spoiler inside an accordion, and I need to open/close them by Javascript. Is there a way to do it ?

    Thanks in advance

    Sylvain

    • This topic was modified 7 years, 6 months ago by sdonnet.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Vova

    (@gn_themes)

    Hi Sylvain,

    Shortcode/HTML (paste it right into post content):

    [su_spoiler class="my-js-spoiler"]Hidden content[/su_spoiler]
    
    <button onclick="toggleMyJSSpoiler()">Toggle Spoiler</button>

    JS code (use it somewhere on your page):

    function toggleMyJSSpoiler() {
    
      var allSpoilers = document.getElementsByClassName('my-js-spoiler');
      var firstSpoiler = allSpoilers[0];
    
      firstSpoiler.classList.toggle('su-spoiler-closed');
    
      return false;
    
    }
    Thread Starter sdonnet

    (@sdonnet)

    Ha ! Thanks a lot !

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Spoiler open/close by JS’ is closed to new replies.