How to pass a variable after setInterval completes?
I have the following code. A fiddle I started which is an isolated version
of something I am trying to do.
var height;
var count = 0;
var setHeight = setInterval(function() {
count++;
console.log('count');
if ( count > 10)
{
console.log('done');
height = 20;
clearInterval(setHeight);
}
},100);
console.log('this is the height -> ' + height);
What I would expect (or want to happen) is for the value of height = 20;
to be outputted in my console.log. The end goal would be to retrieve a
variable from my setInterval function after the interval has been cleared.
Right now I get .. this is the height -> undefined
FIDDLE:
http://jsfiddle.net/GNvG6/8/
What I am trying to accomplish:
So the underlying issue is this. I have a function that runs before some
elements are loaded in the DOM. So what I am trying to do is keep running
the function until an instance of that element exists. Once that happens I
then intend to get the height of that element and hand it off to another
variable. I am not sure If this will resolve my issue, but I figure if I
can get this to work I can at least test it out.
No comments:
Post a Comment