Snippets / JS
JS
Hide empty elementor Tabs
M
medodoha84
·
143 views
·
Updated 1 year ago
We know after VX Template Tabs Widget deprecated we will use elementor tabs. Sometimes, places don't have the content like others so may be some tabs has no content. this code will hide these empty tabs.
On the page you want this to appear, add an HTML widget (FREE) and paste the code in there. Be sure to have before your code and after the code if it isn't already inserted above.
document.addEventListener('DOMContentLoaded', function() {
setTimeout(function() {
// Find all tab content elements
const tabContents = document.querySelectorAll('.e-n-tabs-content > div[id^="e-n-tab-content-"]');
tabContents.forEach(function(tabContent) {
// A tab is considered empty only if it has no children at all
// OR if it only has empty container elements
let isEmpty = true;
// If the tab has any HTML content at all (not just whitespace)
if (tabContent.innerHTML.trim() !== '') {
// Check for any actual content
// This will detect images, videos, text, buttons, etc.
const allElements = tabContent.querySelectorAll('*');
for (let i = 0; i < allElements.length; i++) {
const element = allElements[i];
// Check if this is a container element
const isContainer = element.tagName === 'DIV' ||
element.tagName === 'SECTION' ||
element.classList.contains('e-con') ||
element.classList.contains('e-con-inner');
// If it's not just a container, the tab has content
if (!isContainer || element.innerHTML.trim() !== '') {
isEmpty = false;
break;
}
}
}
// If the tab is truly empty, hide it
if (isEmpty) {
// Get the tab ID
const tabId = tabContent.getAttribute('id');
// Find the corresponding tab title
const tabTitle = document.querySelector(`button[aria-controls="${tabId}"]`);
if (tabTitle) {
// Hide the tab title
tabTitle.style.display = 'none';
}
}
});
}, 800);
});
JS · 49 lines
Discussion
Ask a question or share how you used this.
Log in
to join the discussion.
No comments yet — be the first.