0

I have to add an event listener to an ::after element using javascript.
I guess I have to select it doing something like:

var varName = document.querySelector('#myElementId::after');

But it doesn't work.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
yZemp
  • 59
  • 8
  • 1
    No, it's not possible, as the `before` and `after` pseudo-elements don't exist in the DOM. – CoderCharmander Sep 03 '20 at 12:12
  • 1
    you cannot target ::before or ::aftter pseudoelement for click events. The best you can do is attach the click handler onto the parent element that houses the elements – gavgrif Sep 03 '20 at 12:12
  • 1
    check this link. I think you can find your answer from there. https://stackoverflow.com/questions/7478336/only-detect-click-event-on-pseudo-element – Zahid Hasan Sep 03 '20 at 12:13
  • Thank you very much – yZemp Sep 03 '20 at 14:56

0 Answers0