0

How can I change ::after or ::before styles with Javascript?

This is my code:

var hh = document.querySelector('.ticket-right');
h = window.getComputedStyle(hh, "::after").getPropertyValue('top');

It returns top value. How can I change this value with Javascript?

Tim Lewis
  • 27,813
  • 13
  • 73
  • 102
alireza_acr
  • 11
  • 1
  • 2
  • 3
    Does this answer your question? [Selecting and manipulating CSS pseudo-elements such as ::before and ::after using javascript (or jQuery)](https://stackoverflow.com/questions/5041494/selecting-and-manipulating-css-pseudo-elements-such-as-before-and-after-usin) – Mark Walet Jun 09 '21 at 20:45
  • 1
    You can use CSS variables. See this answer, written by Temani Afif, in the linked thread above: https://stackoverflow.com/a/49618941/5526624 – Rickard Elimää Jun 09 '21 at 21:07

0 Answers0