Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h1>CSS3</h1> <p>css3 may help you. Lead to w3schools and take a read about <a href="http://www.w3schools.com/cssref/sel_nth-of-type.asp" rel="nofollow">the ":nth-of-type" pseudo selector</a>, or see it in action <a href="http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_nth-of-type_odd_even" rel="nofollow">here</a></p> <p>I would recomend the solution 1 as i think is a better practice.</p> <p><strong>Note</strong>: Both solutions assume the "itemID" will be not the same all the time, so we've to base the element selection on other criteria. This is the reason i added the "item-table" class to the <code>&lt;table&gt;</code> tag.</p> <p><strong>HTML for both solutions</strong></p> <pre><code>&lt;table id="itemsID" class="item-table"&gt; &lt;tr&gt; &lt;!-- header field names go here --&gt; &lt;/tr&gt; @for (int i = 0; i &lt; Item.Count; i++) { &lt;tr&gt; &lt;!-- each item's properties go here --&gt; &lt;/tr&gt; } </code></pre> <p></p> <h2>Solution 1: do it on the stylesheet (recomended)</h2> <pre><code>.item-table tr + tr:nth-of-type(even) { /* styles for the even rows */ } .item-table tr + tr:nth-of-type(odd) { /* styles for the odd rows */ } </code></pre> <p><strong>Note</strong>: <code>tr + tr</code> selects all the <code>&lt;tr&gt;</code> tags after the first one. This is useful to skip the header and apply other style to it. For more info <a href="http://www.w3schools.com/cssref/sel_element_pluss.asp" rel="nofollow">see the element + element reference</a>. </p> <p><strong>Tip</strong>: you could also apply styles only to the header with the <a href="http://www.w3schools.com/cssref/sel_firstchild.asp" rel="nofollow">:first-child pseudo selector</a>, as follows:</p> <pre><code>.item-table tr:first-child { /* styles for the header row */ } </code></pre> <h2>Solution 2: modify your selector on the jQuery query</h2> <pre><code>$('table.item-table tr:even').css({ /* some styles here */ }) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload