0

If I have an element with the following style rule:

.element::before {
  box-shadow: inset 0 0 0 2px white, inset 0 0 0 12px tomato;
}

How can I select this element with Javascript, and check if it contains that specific box-shadow style? Thanks.

Can I do something like this?

const element = document.querySelector('.element::before').hasStyle('      box-shadow: inset 0 0 0 2px white, inset 0 0 0 12px tomato;');
isherwood
  • 58,414
  • 16
  • 114
  • 157
Ralph David Abernathy
  • 5,230
  • 11
  • 51
  • 78
  • Generally speaking it's not good practice to base your application logic on whether styles are present. Use a class on the parent element or some other means of tracking more explicitly. – isherwood Nov 30 '20 at 21:09
  • 1
    @isherwood, I completely agree. Unfortunately, the client is using a 3rd party widget that is poorly built and I'm forced to write the logic this way. – Ralph David Abernathy Nov 30 '20 at 21:14
  • Fair enough. Hopefully Barmar's duplicate helps. If not, let us know. – isherwood Nov 30 '20 at 21:15

0 Answers0