Reputation: 6565
I have the following situation...
<li><asp:LinkButton ID="LinkButton1" runat="server">Link</asp:LinkButton></li>
I'm wanting to be able to set the class (or add to the class attribute) of my list item when I click on the button. So once I click on the LinkButton I want the code to change to something like the following...
<li class="selected"><asp:LinkButton ID="LinkButton1" runat="server">Link</asp:LinkButton></li>
Thanks!
Upvotes: 1
Views: 2571
Reputation: 13599
using jquery it can be as easy as this
$(document).ready(function() {
$("#<%=LinkButton1.ClientId %>").addClass(localStorage.style);
});
$("#<%=LinkButton1.ClientId %>").click(function () {
$(this).parent("li").addClass("selected");
localStorage.style="selected";
});
Upvotes: 1
Reputation: 35407
It is better to perform this on the server, as the response will re-render the page. Thus, making JavaScript changes non-applicable:
Dim parent As HtmlControl = LinkButton1.Parent
parent.Attributes("class") = "selected"
Upvotes: 4