hide a table row tr contain a specific label using css

Viewed 68

Hello please help me here is a table

<table class="variations" cellspacing="0">
  <tbody>
    <tr>
      <td class="label"><label for="pa_1ef722433d607dd9d2b8b7"><span>Ships From</span></label></td>
    </tr>
    <tr>
      <td class="label"><label for="pa_color"><span>color</span></label></td>
    </tr>
  </tbody>
</table>

I want to hide each table row tr that had label for="pa_1ef722433d607dd9d2b8b7"

1 Answers

You can do that using js .You can use document.querySelectorAll() to access all tr inside the table. Then you can check for occurrence of label for="pa_1ef722433d607dd9d2b8b7" inside each. Let me show you the code which is self explanotory-

window.onload=()=>{
var elem=document.querySelectorAll("tr");
var i;
for(i=0;i<elem.length;i++){
  var obj=elem[i];
  if(obj.innerHTML.toString().includes('label for="pa_1ef722433d607dd9d2b8b7"')){
      obj.style.display="none";
    }
}
}

In css it will be harder to access parent element, so it is better to use some javascript

Related