How to set the last-clicked anchor to be a different color from all other links?

前端 未结 3 1917
灰色年华
灰色年华 2021-01-02 07:15
a:link {color:#FF0000} /* unvisited link */
a:visited {color:#00FF00} /* visited link */
a:hover {color:#FF00FF} /* mouse over link */
a:active {color:#0000FF} /* se         


        
相关标签:
3条回答
  • 2021-01-02 07:37

    It wouldn't require jQuery, but it's sure easy to do with jQuery.

    $("a").click(function () { 
          $("a").css("color", "blue");
          $(this).css("color", "yellow");
        });
    
    0 讨论(0)
  • 2021-01-02 07:49

    You don't need Javascript. The CSS pseudo-class that you're looking for is 'focus'.

    ps: it holds the 'last clicked' color only until you click on something else in the page.

    a:link {color:#FF0000}
    a:visited {color:#00FF00}
    a:hover {color:#FF00FF}
    a:active {color:#0000FF}
    a:focus {color:#0000FF}
    <b><a href="#">link 1</a>
    <a href="#">link 2</a>
    <a href="#">link 3</a>
    <a href="#">link 4</a>
    <a href="#">link 5</a></b>

    0 讨论(0)
  • 2021-01-02 07:58

    You definitely can't do it with css.

    With jQuery you could do something like

    $("a").live("click", function() {
        $("a").removeClass("yourHighlightClass");
        $(this).addClass("yourHighlightClass");
    });
    
    0 讨论(0)
提交回复
热议问题