在交替的div中更改表格的单元格背景颜色?

时间:2012-10-24 21:00:26

标签: javascript jquery

更改每个其他div的表格单元格背景颜色的正确语法是什么?

代码示例:

            <table>    
                <div id="alternator">
                    <tr>
                        //stuff here
                    </tr>
                    <tbody>
                        <tr>
                            <td>
                                <table>
                                    //stuff here
                                </table>
                            </td>
                        </tr>
                    </tbody>
                </div>
            </table>

要解释一下,我的表格的一部分包含在ID为ALTERNATOR的Div中 对于页面上出现的每个其他ALTERNATOR,我想更改

中表格单元格的背景颜色

类似的东西:

(#Alternator:odd).AllTableCellsInside().attr(background-color, "grey")

1 个答案:

答案 0 :(得分:0)

看起来是:odd选择器的完美用例:http://api.jquery.com/odd-selector/

$('#alternator tr:odd').css('background-color', 'grey');
相关问题