0

I have a tooltip which is a pseudo element shown when hovering over an image. It works well, the tooltip animates in and out.

I'd also like to be able to trigger showing the pseudo element tooltip with javascript. I've read many posts about javascript being unable to target pseudo elements as they're not part of the DOM, but then I've seen some posts which can, specifically this one and this one.

I just need js to change the opacity of the ::before element, the rest I can do, but I don't even know where to start.

The following is from one of the two links above, it can grab the color of the ::before element;

var color = window.getComputedStyle(document.querySelector('.element'),':before').getPropertyValue('color');

but I'm looking for something to the effect of:

window.setComputedStyle(document.querySelector('.element'),':before').setPropertyValue('opacity',"1.0");

Any help would be much appreciated.

Brad
  • 1,019
  • 1
  • 9
  • 22

0 Answers0