Steve
Steve

Reputation: 2588

Hide all text in element if there is no child element through JQuery

I'll try to be concise for this weird issue.

I am hoping to hide text within a "p" tag if there's no child tag present within it.

As an example, if I have following:-

<p class="myflow"> Text <a href="#"> Some Link </a> </p>

I don't want anything to hide, but if there's following:-

<p class="myflow"> Text  </p>

Then I want "p.myflow" to hide, as there's no child tag.

I apologize for not writing some initial try, as I have no idea how to approach this.

Thanks.

Upvotes: 0

Views: 68

Answers (2)

taesu
taesu

Reputation: 4570

if ( $('p.myflow').children().length < 1 ) {
       $('p.myflow').hide();
}

Upvotes: 2

Fuzzyma
Fuzzyma

Reputation: 8474

One solution would be this:

$('p.myflow:not(:has(*))').hide()

Upvotes: 2

Related Questions