SOLDIER-OF-FORTUNE
SOLDIER-OF-FORTUNE

Reputation: 1654

check if div contains li then removing another element using jquery

If div#FeatureIconsWrapper contains NO li

Then div#productInfoGrid is hidden by either by css or removed completly.

I have tried(is this correct?):

$("div#FeatureIconsWrapper:not(li)")({
    $("div#productInfoGrid").hide();
});

Upvotes: 0

Views: 1091

Answers (3)

Tats_innit
Tats_innit

Reputation: 34107

Please try this:

API: http://api.jquery.com/has/

$(document).ready(function() {

       if ($("div#FeatureIconsWrappet:not(:has(li))")) { //.hide()
               $("div#productInfoGrid").hide();
        }
});

Upvotes: 2

VisioN
VisioN

Reputation: 145408

You can use :has:

if (!$("#FeatureIconsWrapper:has(li)").length) {
    $("#productInfoGrid").hide();   // or remove()
}​

DEMO: http://jsfiddle.net/8T4ka/2/

Upvotes: 4

Adil
Adil

Reputation: 148130

Try this,

Live Demo

if($("div#FeatureIconsWrapper li").length == 0)
{
    $("div#FeatureIconsWrapper").hide();
}

Upvotes: 4

Related Questions