![]()
![]()
This guide explains how to build a layout with vertical buttons on the left that show and hide corresponding content sections on the right, without using the default Tabs widget. This gives you maximum design freedom.
Here is what we’ll be building: A set of distinct, styled buttons in the left column that control which content section is visible in the right column.
30% for the left column (buttons) and 70% for the right column (content).This is the most critical step. We need to tell each button which content section it should control.
content-switcher-btn#content-1content-switcher-btn class but changing the link to correspond to a unique content ID:
#content-2#content-3content-1content-panelcontent-2, content-3, etc.) but keep the CSS Classes as content-panel.This code will handle the logic of showing and hiding the content panels.
</body> - End.<style>
/* Hide all content panels by default */
.content-panel {
display: none;
}
/* Show the first panel by default */
#content-1 {
display: block;
}
/* Style for the active button */
.content-switcher-btn.active-btn {
background-color: #6a63e4 !important; /* Active color */
color: #ffffff !important;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Find all the switcher buttons
const switcherButtons = document.querySelectorAll('.content-switcher-btn .elementor-button-link');
// Find all the content panels
const contentPanels = document.querySelectorAll('.content-panel');
// Function to handle the switch
function switchContent(targetId) {
// Hide all panels
contentPanels.forEach(panel => {
panel.style.display = 'none';
});
// Show the target panel
const targetPanel = document.querySelector(targetId);
if (targetPanel) {
targetPanel.style.display = 'block';
}
// Update active state on buttons
switcherButtons.forEach(button => {
if (button.getAttribute('href') === targetId) {
button.closest('.elementor-widget-button').classList.add('active-btn');
} else {
button.closest('.elementor-widget-button').classList.remove('active-btn');
}
});
}
// Set the first button as active by default
if (switcherButtons.length > 0) {
switcherButtons[0].closest('.elementor-widget-button').classList.add('active-btn');
}
// Add click event listeners to each button
switcherButtons.forEach(button => {
button.addEventListener('click', function(e) {
e.preventDefault(); // Prevent page from jumping to the anchor
const targetId = this.getAttribute('href');
switchContent(targetId);
});
});
});
</script>
That’s it! When you view the page, your buttons will now control the visibility of your content sections, giving you a fully custom and professional-looking interactive element.