DEV Community

Pardip Lal
Pardip Lal

Posted on

How to select all diagonal cells in table ?

<table border="1" style="width:100%" id="table">
Enter fullscreen mode Exit fullscreen mode

1.1
2.1
3.1
4.1
5.1


1.2
2.2
3.2
4.2
5.2


1.3
2.3
3.3
4.3
5.3


1.4
2.4
3.4
4.4
5.4


1.5
2.5
3.5
4.5
5.5


<br> let tableEl = document.getElementById(&quot;table&quot;);<br> let tableRows = document.querySelectorAll(&quot;table tr&quot;);</p> <div class="highlight"><pre class="highlight plaintext"><code>let ind=0; while(tableRows[ind]){ tableRows[ind].cells[ind].style.backgroundColor = "red"; ind++; } &lt;/script&gt; </code></pre></div>

Top comments (0)