mattt
mattt

Reputation: 1471

jQuery Remove Div Based On Content

i would like to remove/hide a li based on the content inside it, is this easy to do?

eg. the code below: if span#type has no content then li.grouping should be removed or hidden.

<li class="grouping"><span class="desc">Options:</span><br /><span id="type"></span></li>

Upvotes: 1

Views: 3011

Answers (2)

Brian Campbell
Brian Campbell

Reputation: 332816

$("li.grouping:has(span#type:empty)").remove()

It would seem to make more sense if type were a class, rather than an id, as there should only be one element with a given id on the page. In that case:

$("li.grouping:has(span.type:empty)").remove()

Upvotes: 3

Aziz
Aziz

Reputation: 20705

maybe something like

if ($("span#type").text() == "") {
    $("li.grouping").hide();
}

Upvotes: 0

Related Questions