You must Sign In to post a response.
  • Category: HTML

    On click of html.actionlink change the hyperlink colour

    i have html.actionlink like this
    <%=Html.ActionLink("click here", "tes", "test", new{filename="a"}, new {@class="", @target="_blank", onclick=TestMethod('"param value"')})%>

    function TestMethod(param)
    {
    ajax call here
    }

    I have hyperlink value as 'Click here' with a default colour. Now on click of 'Click here' i need to change the color to gray. How to achieve this
  • #769137
    Hi,

    There are many easy approaches we can make this work out,


    @Html.ActionLink("WareHouse", "WareHouseIndex", "Admin", null, new {style = "color:grey"});


    There is also a dynamic way,


    Html.ActionLink("My Link", "MyAction", null, new { @class = "my-class" }) . Then create a CSS a.my-class { color: #333333 } a.my-class:active { color: #fffffff} a.my-class:link { color: #3333 } a.my-class:visited { color: #CCCCCC }


    So color can be taken dynamically with the help of CSS.

    Thanks,
    Mani

  • #769155
    Basically has the browser has the ':visited' pseudo class from which if any link is clicked, its color changes to brown from blue, now if you want to change it to some custom color then you can try below JQuery snippet

    $('a').click(function(){
    $(this).addClass("visited");
    });

    //and the CSS
    a{
    color:#000;
    text-decoration:none;
    }

    a.visited{
    color:#205081;
    }

    ....
    ....
    < script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>// import jQuery
    < script>
    enter the script here..
    < /script>
    < /body>

    hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


  • Sign In to post your comments