Change CSS Link Property onClick with Javascript/JQuery?

后端 未结 7 2113
长情又很酷
长情又很酷 2021-01-01 04:34

So for example i have two links:

Link 1
Link 2
<
7条回答
  •  萌比男神i
    2021-01-01 05:13

    Your default CSS colour for links should be:

    a:link {
        color: #0f0; /* or
        color: green;
        color: rgb(0,255,0);
    }
    

    Otherwise, using jQuery, you can achieve this with:

    $('a').click(
        function(){
            $('.selectedLink').removeClass('selectedLink');
            $(this).addClass('selectedLink');
            return false
        });
    

    Coupled with the CSS:

    .selectedLink {
        color: #00f;
    }
    

    JS Fiddle demo.

提交回复
热议问题