1. PROMO Subscribe our All Access Pass @ 75% OFF & access all our 16+ premium Divi extensions: Divi Block Pro, Carousel Toolkit, etc.LEARN MORE
Dismiss Notice
NEW Divi.Help Pro Carousel AI Toolkit - Magically turn your Divi design into carousel, simply by using our online toolkit. No plugins needed. Now it works with Divi 5 as well!Try our carousel AI toolkit
BEST Divi Block - A revolutionary drag & drop tool to easily mix & match 960+ premade blocks (Light & Dark) to kick start your Divi site design. Special module designs are included as well. Also newly added AI generator & color. Now it works with Divi 5 as well!
Learn More About Divi BlockFree Version ~ 340+ Free Blocks

Adding if/this to change text of a Button module after clicking

Discussion in 'Free Divi Community Forum' started by Srossi, May 19, 2021.

  1. Srossi

    Srossi New Member

    Hello beautiful people,

    I currently have 3 buttons on a divi site that hide/reveal sections but would like the text to change on the buttons themselves from 'Learn More' to 'Close' whenever the sections are expanded and collapsed. Does anyone know of some JS I can plug into the code below to do this?

    Here is the JS im using in a code module for the hide/reveals:
    <script type="text/javascript">
    //First part
    jQuery(document).ready(function() {
    jQuery('#reveal_1').hide();
    jQuery('.rv_button_1').click(function(e){
    e.preventDefault();jQuery("#reveal_1").slideToggle();
    jQuery('.rv_button_1').toggleClass('opened closed');
    jQuery("#reveal_2").hide();
    jQuery("#reveal_3").hide();
    });
    });
    //Second part
    jQuery(document).ready(function() {
    jQuery('#reveal_2').hide();
    jQuery('.rv_button_2').click(function(e){
    e.preventDefault();jQuery("#reveal_2").slideToggle();
    jQuery('.rv_button_2').toggleClass('opened closed');
    jQuery("#reveal_1").hide();
    jQuery("#reveal_3").hide();
    });
    });
    //Third part
    jQuery(document).ready(function() {
    jQuery('#reveal_3').hide();
    jQuery('.rv_button_3').click(function(e){
    e.preventDefault();jQuery("#reveal_3").slideToggle();
    jQuery('.rv_button_3').toggleClass('opened closed');
    jQuery("#reveal_1").hide();
    jQuery("#reveal_2").hide();
    });
    });
    </script>

    Here is the CSS im using that changes the icons:
    .rv_button_1.closed:after {content:"\4c";}
    .rv_button_1.opened:after{content:"\4d";}
    .rv_button_2.closed:after {content:"\4c";}
    .rv_button_2.opened:after{content:"\4d";}
    .rv_button_3.closed:after {content:"\4c";}
    .rv_button_3.opened:after{content:"\4d";}


    Thank you.
     
    1. PRO MEMBER PERKS Divi.Help Pro Layout Packs - Agency Divi layout pack featuring modern overlay archive blog layout with hover effects:View Demo
  2. Divi.Help

    Divi.Help Administrator
    Staff Member

    Here's the jQuery to change the text:
    Code:
    Log In or Sign Up to view this code.