Show/Hide a Section on Button Click for Elementor Pro & WordPress

Welcome to this beginner-friendly tutorial on how to create a show/hide functionality for sections using a button click in Elementor on WordPress. By the end of this tutorial, you’ll be able to create a button that, when clicked, will show or hide a specific section on your page. This can be useful for creating interactive elements on your website, such as FAQs, spoiler alerts, or simply to save space and create a cleaner layout.

Step 1: Install Elementor and Elementor Pro
First, make sure you have both Elementor and Elementor Pro installed on your WordPress site. You’ll need Elementor Pro to access some of the features we’ll be using in this tutorial.

Step 2: Create or Edit a Page with Elementor
Create a new page or edit an existing one using Elementor. You can do this by navigating to Pages > Add New (or by editing an existing page) and clicking on the “Edit with Elementor” button.

Step 3: Add a Button Widget
Drag and drop a Button widget onto your page. This will serve as the trigger to show or hide the section.

Step 4: Customize the Button
Customize the button’s text, appearance, and other settings to your liking.

Step 5: Add an HTML Widget
Drag and drop an HTML widget below the button. This will serve as the container for our custom JavaScript code.

Step 6: Add JavaScript Code
Paste the following code snippet into the HTML widget:

document.addEventListener("DOMContentLoaded", function() {
  const button = document.querySelector("#your-button-id");
  const section = document.querySelector("#your-section-id");

  button.addEventListener("click", function() {

.hidden {
  display: none;

Step 7: Replace IDs in the Code
Replace your-button-id and your-section-id with the actual IDs of the button and section you want to show or hide. You can find these IDs by clicking on the widgets and checking the “Advanced” tab under the “CSS ID” field.

Step 8: Save and Test
Save your page and preview it. Click the button to test if the section shows and hides as expected.

Congratulations! You’ve successfully added a show/hide functionality to your Elementor page on WordPress. With this knowledge, you can create more interactive and engaging elements on your website to improve user experience. Remember, you can use this same technique to show or hide multiple sections with different buttons. Keep experimenting and happy designing!