Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1489329

    I am very evidently not good with javascript, but was hoping to follow “recipe” on

    to Show/Hide a section.

    I was trying to create what’s entitled

      Toggle a Section when a button is clicked.

    At end of functioning functions.php, I inserted the following code and got the error indicated in the subject line above.

    The debug indicates an [18-Sep-2025 01:04:06 UTC] EXCEPTION: Unclosed ‘{‘ on line 1367 in functions.php on line 1393 — that appears to be right on the line prior to the add_action. If I put in } (to close it?), I still get the error.

    Please, could somebody steer me right on this thing? I’m befuddled!

    Thanks for any help from an expert!
    ======================================================================================

    //——————————-
    // Toggle section
    //——————————-

    function toggle_on_click(){
    ?>
    <script>
    jQuery(window).on(‘load’, function(){

    // Button onClick event

    jQuery(“.toggle-button a”).on(“click”, function(e) {

    // Add your button events here

    console.log(” toggle section”);

    jQuery(“#toggle-section”).toggleClass(“hide-me”);

    console.log(” Prevent default “);

    e.preventDefault();

    });

    });
    </script>
    <!–?php<br /–> }

    add_action(‘wp_footer’, ‘toggle_on_click’);

    #1489330

    `<a href=”http://[18-Sep-2025 01:04:06 UTC] EXCEPTION: Unclosed ‘{‘ on line 1367 in /home/calvarybaptistdu/public_html/wp-content/themes/enfold-child/functions.php on line 1393″>Toggle a section when a button is clicked</a>

    #1489334

    Hi,

    Thank you for the inquiry.

    There is invalid code in the snippet. Please remove it and replace it with the following code:

    //——————————-
    // Toggle section
    //——————————-
    
    function toggle_on_click() {
        ?>
        <script>
        jQuery(window).on('load', function() {
    
            // Button onClick event
            jQuery(".toggle-button a").on("click", function(e) {
    
                // Add your button events here
                console.log("Toggle section");
    
                jQuery("#toggle-section").toggleClass("hide-me");
    
                console.log("Prevent default");
    
                e.preventDefault();
            });
    
        });
        </script>
        <?php
    }
    
    add_action('wp_footer', 'toggle_on_click');
    

    Best regards,
    Ismael

    #1489357
    This reply has been marked as private.
    #1489382

    Hi,

    Thank you for the update.

    Did you place the code somewhere else? It’s not working because the scripts are loading before jQuery. Please provide the login details in the private field so we can check further.

    Best regards,
    Ismael

    #1489410

    Interesting…I don’t THINK I did…but will search through code and let you know.
    Don’t want to bother you if I can find it myself. Hopefully, I will find!

    #1489439

    Hi,

    Please feel free to update us if you’re not able to identify the issue. We’re happy to assist.

    Best regards,
    Ismael

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.