Reputation: 151
The URL to the page is this.
And the screenshot to the questioned area is this.
I want, if the accordion has no content, then hide the accordion title itself. Empty accordion elements won't show.
I have used this script for that:
jQuery(".su-spoiler-content:empty").parent().hide();
But I can't find it doing anything.
Is there anything wrong in the above code?
Upvotes: 0
Views: 85
Reputation: 1
Like pointed before, the element can have some children inside. Based on other answers (and litle help from my friends), I wrote this piece of jquery code.
$('.accordion-body').each(function (index, element) {
if (element.children.length == 0) {
$(this).parent().parent().hide()
}
})
It may be useful for other people looking for.
Upvotes: 0
Reputation: 22431
try that...
document.querySelectorAll('div.su-spoiler-content').forEach(xDiv=>
{
if (xDiv.innerText.trim() === '')
xDiv.closest('div.su-spoiler').style.display = 'none'
})
Upvotes: 2
Reputation: 75
It seems that you have "invisible stuff" inside your div.
I just edit as HTML in the browser and it works
Upvotes: 1