active pseudo class not working

前端 未结 2 947
青春惊慌失措
青春惊慌失措 2021-01-25 19:07

when i click on the link \"home\" class home should change and stay at class home1 till another link is clicked but it doesn\'t...class changes but on clicking the other link

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-25 19:56

    The :active-state is only active while you hold down the mouse-button on the link! It is not active until you click another link! This could be done with jQuery:

    $('a').click(function() {
        $('a.lastClickedLink').removeClass('lastClickedLink');
        $(this).addClass('.lastClickedLink');
    });
    

    The link that was clicked last will have the class lastClickedLink and can then be styled through css with a.lastClickedLink {}.

    If you want this class to be persistent when the user comes back to the page later, you will have to use a cookie. Use jQuery cookie for this.

提交回复
热议问题