2

I have a pseudoclass element(:after to be specific), and I want to scroll to top when I click on it. Somehow this does not work...

I tried this:

$('.someclass:after').click(function () {
    $("html, body").animate({
        scrollTop: 0
    }, 600);
    return false;
});

And it does not work. When I use just the normal class, it works perfectly:

  $('.someclass').click(function () {...});

So I assume, the code works, jquery works, but somehow not with a pseudoclass selector. How can I fix this? To use a normal class is not an option, it has to be my :after class selector.

Thank you!

1 Answers1

0

As far as I've heard, you can't select or attach events to pseudo elements because they don't actually exist in the DOM. As linked in a comment above, you can change the attribute that the pseudo element displays using Javascript (since you target the parent) but not the psuedo.

Donnie D'Amato
  • 3,832
  • 1
  • 15
  • 40