I have an external JavaScript function running on a page that is out of my control. This JavaScript's final action is to set a div on the page's visibility to hidden. I want to run a function as soon as the div is set to be hidden.

How do I use jQuery to notify me when the div's CSS becomes hidden?

3 answers

danwellman 5600
5
points
This was chosen as the best answer

You could use a simple setInterval timer to periodically poll the div to check its visibility, something like:

function divpoll() {
  if($("#thediv").css("visibility") === "hidden") {
    myOtherFunction();
  }
}

setInterval("divpoll", 500);

This would query the CSS of the div every 500 milliseconds and call your other function when the condition matches.

The above is psuedocode, so it may need a little tweak for it to work correctly but that should essentially do what you need, but it could be fairly intensive, especially for older browsers :)

Answered over 7 years ago by danwellman
3
points

@danwellman's suggestion is about the only surefire way to do it. But do you have no access to that function's namespace whatsoever? Is there no way you could override it? something to the tune of...

$functionInQuestion = function() {
    $functionInQuestion();
    triggeredFunction();
}
Answered over 7 years ago by Simon Scarfe
0
points

You can also just run through a loop or any sort of logic that checks for the jQuery-specific :hidden pseudo-class.

Answered over 7 years ago by Nathan DeGruchy