0

I want to change the css of one td through jquery. Please help on this. This is not working for me $("#tdTopMenu").css({ "backgroundColor": "black", "color": "white" });

aspx code:

 <table border="0" cellspacing="0" width="100%">
    <tr>
        <td id = "tdTopMenu" runat = "server" style="width: 100%" class="hideColumn">
            <asp:Literal ID="Literal1" runat="server"></asp:Literal>
        </td>
    </tr>
</table>

Jquery code:

<script type="text/javascript">
        $(document).ready(function () {

            $("#jMenu").jMenu({
                ulWidth: '150',
                effects: {
                    effectSpeedOpen: 300,
                    effectTypeClose: 'slide'
                },
                animatedText: false
            });

            $("#tdTopMenu").css({ "backgroundColor": "black", "color": "white" });    
        });

      </script>
4

3 回答 3

1
id != tdTopMenu

删除元素上的 runat = "server" 并重<td>

于 2013-08-06T09:09:54.087 回答
1

尝试这个:

 $("#"<%=tdTopMenu.ClientID%>).css("backgroundColor","black").css("color","white");
于 2013-08-06T09:10:15.190 回答
1
$("#<%=tdTopMenu.ClientID%>").css({ "backgroundColor": "black", "color": "white" });

ASP.NET Web 窗体在将 ID 呈现为 HTML 时会更改这些 ID,因此您需要检索客户端 ID,而不是使用服务器 ID。

或者,您可以将 ClientIdMode="Static" 添加到 tdTopMenu。

于 2013-08-06T09:11:43.860 回答