JQuery - Hide a specific div

I have several divs that have a common class. If one of these divs has a non- child div, I want to hide the div. I can find the correct div, but I cannot hide it.

This is my code,

$(function() {

        if ($(".adRight.childen('div')").length == 0) {
            $(this).hide();

        }

    });

What should i use instead? this applies to the document, not the div found by the if-statement.

+3
source share
2 answers

You are looking for:

$("div.adRight:not(:has(div))").hide();

How does he read.

(, .childen ), , , jQuery. .
, if -, jQuery ( ). jQuery - , 0. 0 .
, , hide, - hide , .

+5

:

if ($ ( ". adRight div" ) == undefined) {           $ ( "AdRight." ) ().       }

(~~ )

0

Source: https://habr.com/ru/post/1736083/


All Articles