Skip to content Skip to sidebar Skip to footer

Check If Image Does NOT Exist Then Hide A Div

If there is an image in the div then hide the div. But if the image does exist then i need to keep the div visable. But its not working. Here is my code: HTML: Copy

or simpler

$("#productInfoGrid").not(':has("img")').hide();​

DEMO


Solution 2:

if ($("#productInfoGrid img").length == 0) {
    $("#productInfoGrid").hide();
}

Solution 3:

$("div#productInfoGrid").has('img').hide();

Demo

Note

$("#div#productInfoGrid:not(img)") should be $("div#productInfoGrid:not(img)")


Solution 4:

You can use .find() (Reference: http://api.jquery.com/find/)

if ($("#productInfoGrid").find('img').length == 0) {
    $("#productInfoGrid").hide();
}
​

Post a Comment for "Check If Image Does NOT Exist Then Hide A Div"