Search code examples
javascriptcsshide

Hide all table row with bgcolor


I've got a long table of which some of them has a bgcolor attribute:

<tr bgcolor="#EAE5C2">

I want to hide this rows with js. Is there any way to target only this rows and Possibly apply a display: none; css?


Solution

  • in CSS you can use an attribute selector

    tr[bgcolor] { display: none }
    

    otherwise in Javascript select all the elements via document.querySelectorAll('tr[bgcolor]')

    e.g.

    document.querySelectorAll('tr[bgcolor]').forEach(
      (r) => r.style.display = 'none';
    );