How to hide div if other divs not exists in Javascript

تبليغ
سؤال

يرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.

تبليغ
‎إلغاء

I’m trying to hide the div title if related divs are no present:

Main HTML structure:

<div class=”row parent”>
<div id=”title-1″ class=’col-12 prov-title’>
<h2>$category->name</h2>
</div>
<article id=”child-11″ class=”col-md-6 mb-4 child”>
… Content …
</article>
<div id=”title-2″ class=’col-12 prov-title’>
<h2>$category->name</h2>
</div>
<article id=”child-21″ class=”col-md-6 mb-4 child”>
… Content …
</article>
<article id=”child-22″ class=”col-md-6 mb-4 child”>
… Content …
</article>
<div id=”title-3″ class=’col-12 prov-title’>
<h2>$category->name</h2>
</div>
<article id=”child-31″ class=”col-md-6 mb-4 child”>
… Content …
</article>
<article id=”child-32″ class=”col-md-6 mb-4 child”>
… Content …
</article>
<article id=”child-33″ class=”col-md-6 mb-4 child”>
… Content …
</article>

</div>

Filtering the content I get:

<div class=”row parent”>
<div id=”title-1″ class=’col-12 prov-title’>
<h2>$category->name</h2>
</div>
<article id=”child-11″ class=”col-md-6 mb-4 child”>
… Content …
</article>
<article id=”child-12″ class=”col-md-6 mb-4 child”>
… Content …
</article>
<div id=”title-2″ class=’col-12 prov-title’>
<h2>$category->name</h2>
</div>
</div>

I mean, I need to hide the #title-2 div if #child-21 and #child-22 layers are not shown.

I understand that you would have to make a loop and look for .child pages by ID that start with the same number as the corresponding title div and hide it. I don’t know much about the wildcards in the references to the id…

What would be the best way to do it in javascript?

Thnaks,

0
X 5 أشهر 2022-07-10T12:03:11+03:00 0 إجابة 1 مشاهدات مبتدئ 0

‫أضف إجابة

تصفح
تصفح

مجهول يجيب