79279010

Date: 2024-12-13 16:50:09
Score: 1.5
Natty:
Report link

You can refer the following code. You need to check whether selector1 has class show or hide and then apply the conditions.

However, the selector2 ie empty tr element not taking style hence I have added some text.

Please let me know if you get to know the reason.

const selector1 = document.querySelector('.selector1');
const selector2 = document.querySelector('.selector2');

if (selector1.classList.contains('show')) {
    document.getElementById('selector2').innerText = 'somehow styles not applying on empty tr';
  document.getElementById('selector2').style.backgroundColor = 'rgba(255, 255, 0)';
}

if (selector1.classList.contains('hide')) {
    document.getElementById('selector2').innerText = 'somehow styles not applying on empty tr';
  document.getElementById('selector2').style.backgroundColor = 'rgba(255, 0, 0)';
}
.selector1 {
  background-color: red;
  width: 200px;
  padding: 10px;
}

table thead tr .selector2 {
  padding: 10px;
  width: 200px;
}
<div>
  <div class="selector1 hide"></div>
  <div class="div2">
    <div>
      <div>
        <div class="div3"></div>
        <div class="div4"></div>
        <div class="div5">
          <div class="div6"></div>
          <div class="div7"></div>
          <div class="div8">
            <table>
              <thead>
                <tr class="selector2" id="selector2"></tr>
              </thead>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

Hope, this helps.

Reasons:
  • RegEx Blacklisted phrase (2.5): Please let me know
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Naeem Akhtar