check if image does NOT exist then hide a div

前端 未结 4 949
猫巷女王i
猫巷女王i 2021-01-24 15:36

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:

4条回答
  •  花落未央
    2021-01-24 16:22

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

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

提交回复
热议问题