Change Class of html link in Master Page


I am in process of learning I need to know how to change class of a link which is in Mater page from Default.aspx

For example, in following example I would like to change/update the class of “Home” link.

  <div align="right">
        <a href="Default.aspx" id="lnkHome" class="">Home</a>
        <a href="AboutUs.aspx" id="lnkAbout"  class="">About Us</a>
    <div class="Clear"></div>

As I am learning, so please suggest the ways to do above.


On your master page code behind create a method like this:
public string MyLinkClass
set { mylink.attributes.add(“class”,value; }

Then on any page you like to set the class for that link:
MyMasterPage master=(MyMasterPage)this.Page.Master;


Thanks for your response.
The given solution is not working on my end, as it says “lnkHome” is not declared. Again the html code I have is:

<a href=“Default.aspx” id=“lnkHome” class=“”>Home</a>

Is there any way to access HTML elements (not html elements that run at server)?

you are missing the runat=“server” attribute.

<a href=“Default.aspx” id=“lnkHome” class=“”>Home</a>
should be
<a href=“Default.aspx” id=“lnkHome” runat=“server” class=“”>Home</a>