:target selector

test about jQuery :target selector

by Yohan Yang

HTML

<p>
    <a href="#first">first</a>
    <a href="#">second</a>
    <a href="#third">third</a>
</p>

<p id="first">
    this is first P.
</p>
<p id="second">
    this is second P.
</p>
<p id="third">
    this is third P.
</p>

CSS

.on {
    background-color: yellow;
    color: red;
}

JavaScript

$(window).on('hashchange', function () {
    $('p span').remove();
    $('p').removeClass('on');
    $(':target').addClass('on').append('<span> [selected]</span>');
});