Jituu
Jituu

Reputation: 151

Hide div is child is empty

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

Answers (3)

giofronza
giofronza

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

Mister Jojo
Mister Jojo

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

Charles Xavier
Charles Xavier

Reputation: 75

It seems that you have "invisible stuff" inside your div.

enter image description here

I just edit as HTML in the browser and it works

enter image description here enter image description here

Upvotes: 1

Related Questions