1

In a css style I have the following

.back::after  {
    content: "";
    background-image: url(../images/patch.png);
    background-repeat: repeat;
    opacity: 0.6;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    position: absolute;
    z-index: -1;

}

anyway using jQuery : $(".back ::after").css("opacity","0.9") to select the ::after element to change opacity doesnt work ! any idea how to do this ?

ProllyGeek
  • 15,517
  • 9
  • 53
  • 72

3 Answers3

4

As already mentioned, you cannot target the pseudo-elements, because they don't really exist in the DOM.

You could simply add an additional CSS rule and target the related element instead:

.back.focus::after  {
    opacity: 0.9;
}

and

$('.back').addClass('focus');
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
0

Try just using one colon, i.e.: .back:after. Leave a comment if it still doesn't work.

Chris M
  • 209
  • 1
  • 3
0

well , thanks for the neat solutions , but i think this one fits me the most as i can control it easily , injecting my own style dynamically and removing it.

document.styleSheets[0].insertRule('.back::after { opacity: 0.9 !important; }', 0);
ProllyGeek
  • 15,517
  • 9
  • 53
  • 72