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>
3
  • 2
    Your code works fine. See jsfiddle.net/ByhgD Commented Aug 6, 2013 at 9:08
  • did u check if it has anything to do with class="hideColumn" which you have added in yoru td tag? Commented Aug 6, 2013 at 9:10
  • Thank you Nitin... its working now... In hide column i was mentioned display none... now changed that to block in jquery... its working fine Commented Aug 6, 2013 at 9:22

3 Answers 3

1
$("#<%=tdTopMenu.ClientID%>").css({ "backgroundColor": "black", "color": "white" });

ASP.NET Web Form changes the IDs when they are rendered to HTML so you need to retrieve the client-side id, rather than using the server ID.

Alternatively you can add ClientIdMode="Static" to tdTopMenu.

Sign up to request clarification or add additional context in comments.

Comments

1
id != tdTopMenu

delete runat = "server" on element <td> and re try

Comments

1

Try this:

 $("#"<%=tdTopMenu.ClientID%>).css("backgroundColor","black").css("color","white");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.