
Tagged: $eof, Hide, javascript, Section, show
-
AuthorPosts
-
September 18, 2025 at 3:14 am #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’);
September 18, 2025 at 3:16 am #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>
September 18, 2025 at 4:44 am #1489334Hi,
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,
IsmaelSeptember 18, 2025 at 2:20 pm #1489357This reply has been marked as private.September 19, 2025 at 4:42 am #1489382Hi,
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,
IsmaelSeptember 19, 2025 at 8:39 pm #1489410Interesting…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!September 22, 2025 at 5:16 am #1489439 -
AuthorPosts
- You must be logged in to reply to this topic.