0

Using JavaScript to change CSS visibility is trivial

element.style.visibility = 'visible'
element.style.display = 'block'

but, is it possible to go the other way, that is, trigger JS when CSS visibility changes? For example

#element {
   visibility: hidden;
   display: none;
}

#element::target {
   visibility: visible;
   display: block;
}

When a user clicks on element, I want aFunction() to fire with access to info about the element's DOM properties. I am assuming that is not possible but asking just in case…

punkish
  • 13,598
  • 26
  • 66
  • 101
  • https://stackoverflow.com/questions/55590763/set-style-change-event-listener-in-javascript? – evolutionxbox Jul 28 '21 at 20:04
  • Not sure I understand - is there a reason for not sensing the click event and firing the function? – A Haworth Jul 28 '21 at 20:05
  • 1
    @evolutionbox, thanks for the link to the `MutationObserver` question. It almost (but not quite) does what I want but, on the other hand, I learned something new :) @a-haworth I was not using a click even but instead using the CSS pseudoclass `:target` to change visibility, and wanted to fire a function when the visibility changed. Anyway, have decided to implement a different approach. Thanks all. Am closing the question. – punkish Jul 28 '21 at 20:25

0 Answers0