N
N
neytan2018-03-18 18:46:59
JavaScript
neytan, 2018-03-18 18:46:59

Check an element for the presence of a specific child and hide the parent if the element is not found?

Hello, I have this code:

<section class="main-text">
  <div class="container">
    <div class="row">
      <h3>Заголовок</h3>
    </div>
  </div>
</section>

How can I use jquery to check the .main-text section for the presence of h3 in it, and make the .main-text section hidden if it does not have an h3 header.
I sketched the code, but apparently something is wrong:
if ($(".main-text:not(:has(.children(h3)))") ) {
    $(".main-text").hide();
  };

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2018-03-18
@neytan

if .main-text and h3 are in a single instance, then you are too smart

if ($(".main-text h3").length ==0 ) {
    $(".main-text").hide();
  };

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question