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…

3
  • stackoverflow.com/questions/55590763/…? Commented Jul 28, 2021 at 20:04
  • Not sure I understand - is there a reason for not sensing the click event and firing the function? Commented Jul 28, 2021 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. Commented Jul 28, 2021 at 20:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.