-2

I have a css after element that needs to function like a back to top of page button but for some reason the hover state and jQuery click function do not seem to work. Not sure if its maybe a syntax error that I am missing?

HTML

<div id="divMain">
    ::after
</div>

CSS:

#divMain:after { content: 'Back  To Top'; position: relative; left: 93%; font-size: 16px; bottom: 30px; cursor: pointer; padding: 5px 10px; }
#divMain:after:hover { color: #b0f14f; }

JS/jQuery:

$('#divMain:after').click(function () {
        $('html, body').animate({ scrollTop: 0 }, 'fast');
    });
Mikey
  • 366
  • 1
  • 4
  • 20

1 Answers1

-1

https://stackoverflow.com/a/17789110/3381024

the :after selector cannot be reached by jquery as it is not technically part of the DOM.

if you are using jquery anyway, append another class to it. however for the use of an absolutely positioned element, not sure why :after would be needed when you can just make a new element and style it up anyway

Community
  • 1
  • 1
LiamHT
  • 1,312
  • 3
  • 12
  • 28