Set visited link color to whatever the color of un-visited link is (P.S. not the usual question)

前端 未结 10 1762
执念已碎
执念已碎 2021-02-03 16:59

I need to set the a:visited CSS to whatever color the normal a is set to.

What I want to be able to tell the browser is, for the visited links, use the same

10条回答
  •  生来不讨喜
    2021-02-03 17:33

    There is no way to do this using CSS. The browser indicates that a link has been visited based upon a database entry only it knows about, and then uses default colours specified in the specific browsers configuration.

    CSS physically just cannot obtain the colour of something on the page. That is just the way it is. The only way is to use javascript like Danny Roberts' answer.


    The reason I think that his answer is not working correctly is that $('a:visited') just selects all the visited links at that point in time and then the colour is changed for them.

    What you need to do is watch for click events and re run the code each time:

    var normalColor = $('a:link').css('color');
    $('a').click(function() {
        $('a:visited').css('color', normalColor);
    });
    

提交回复
热议问题