-1

here is my code :

.back-div::after {
    background: black;
    content: "";
    opacity: 100%;
    position: absolute;
    display: none;
    width: 100%;
    top: 0;
    left: 0;
    opacity: 70%;
    height: 100%;
    z-index: 100;
}

how to get or find backdiv::after ?? please give the simplest way because I don't know even one library

Alberto Sinigaglia
  • 12,097
  • 2
  • 20
  • 48

2 Answers2

0

you can do something like this:

let color = window.getComputedStyle(
    document.querySelector('.back-div'), ':after'
).getPropertyValue('color')
Alberto Sinigaglia
  • 12,097
  • 2
  • 20
  • 48
0

Here's how to get the properties of the pseudo selector and a quick demo on how to switch classes (the best way to 'affect' css rules with pseudo selectors)

let theStyle = window.getComputedStyle(document.querySelector('.exciting-text'), ':after')
console.log(theStyle.content)
console.log(theStyle.color)

setTimeout(function() {
document.querySelector('.exciting-text').classList.add('boring-text')
document.querySelector('.exciting-text').classList.remove('exciting-text')
}, 1500)
.exciting-text::after {
  content: " <- EXCITING!";
  color: green;
}

.boring-text::after {
  content: " <- BORING";
  color: red;
}
<p class="boring-text">Here is some plain old boring text.</p>
<p class="exciting-text">Contributing to MDN is easy and fun.</p>
Kinglish
  • 23,358
  • 3
  • 22
  • 43