开发者

Selecting even rows of specific css class

I'm trying to select the even rows of a table of a certain class.

So the table looks like this:

Absolute row 1 -- virtual row 1 of class a
Absolute row 2 -- virtual row 2 of class a (should be matched by css selector)
Absolute row 3 -- virtual *row 1* of class b
Absolute row 4 -- virtual row 3 of class a
Absolute row 5 -- virtual row 4 of class a (should be matched by css selector)

I tried using this selector:

.table-result tbody tr.include:nth-child(even) {background-color: #eeeeee;}

but it still keeps the tr's with a different class in mind

Is there a way around this? Without having to resort to tables inside of tables?

HTML:

    <table class="ui-widget ui-widget-content table-result" id="adspaceresult">
        <thead>
            <tr class="ui-widget-header">
                <th>Type</th>

                <th>Info</th>

                <th>Average</th>

                <th>Bid</th>

                <th>Graph</th>
            </tr>

        </thead>

        <tbody id="adrbody">
            <tr class="include">
                <td><button data-adtype="1" data-adspaceid="2" class="resultbutton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"><span class="ui-button-text">Micro Bar<br>
                88x31</span></button></td>

                <td></td>

                <td>77</td>

                <td>Bid</td>

                <td>Graph</td>
            </tr>

            <tr>
                <td colspan="5">Why hello there!</td>
            </tr>

            <tr class="include">
                <td><button data-adtype="1" data-adspaceid="3" class="resultbutton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"><span class="ui-button-text">Micro Bar<br>
                88x31</span></button></td>

                <td></td>

                <td>748102</td>

                <td>Bid</td>

                <td>Graph</td>
            </tr>

            <tr class="include">
                <td><button data-adtype="1" data-adspaceid="5" class="resultbutton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"><span class="ui-button-text">Micro Bar<br>
                88x31</span></button></td>

                <td></td>

                <td>226</td开发者_JS百科>

                <td>Bid</td>

                <td>Graph</td>
            </tr>

            <tr class="include">
                <td><button data-adtype="1" data-adspaceid="6" class="resultbutton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"><span class="ui-button-text">Micro Bar<br>
                88x31</span></button></td>

                <td></td>

                <td>6003</td>

                <td>Bid</td>

                <td>Graph</td>
            </tr>
        </tbody>
    </table>

The tr containing the "why hello there" message should not be counted for.


select the rows by classname and select the alternate element

var list = $(".include")
for (i=0;i<list.length-1;i++)
 {
 if (i%2 == 0){
  // do what you want
 }
}


Can be don't if you have limited number of rows, but I wouldn't advise using it

table .b, table .b~.b~.b, ... {background:white;}
table .b~.b, table .b~.b~.b~.b, ...{background:blue;}

example http://jsbin.com/exuzex/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜