SanJeet Singh SanJeet Singh - 1 year ago 94
CSS Question

jQuery :target selector doesn't work

Here is my Markup:

<p>A paragraph with <a id="link" href="#link">a link</a> inside it.</p>

Here is my jQuery:


When I click on the link, the URL changes to
. However, the
does not increase.
There is no change in
even if I directly load

Why is the selector not working?

Update: I have to use the
selector. There is no choice.

Answer Source

This is your problem that you used :target selector immediately after anchor clicking. When you click on anchor, javascript run your selector immediately while browser doesn't focus on target element. You need to pause your code for miliseconds then run :target selector.

    }, 1); 
<script src=""></script>
    A paragraph with 
    <a id="link" href="#link">a link</a>
    inside it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download