Is there a way to have javascript coffee always be checking the document? What I mean by this is if I have "if" statements, it will always check the document to see if it needs to run the script...

Also, it needs to not be a function that needs to be called. Here is some simple example of what I'm asking.

<button id="btn1">random button</button> <button id="btn2" onclick="hide()">hide</button> <script> function hide() { document.getElementById("btn1").setAttribute("hidden", "true") } </script> <script> if (document.getElementById("btn1").hidden === true) { document.write("random button is hidden") } </script>

How would I do something like this? I don't want this specifically, this is just an example.

In the code,a button hides another one, and there is script always checking if it is hidden. Please let me know.

edit

I see other people's answers, but it's not what I need. Is it possible to have functions constantly run without being called?