In this case you need to wrap the code inside the onclick in a function: onclick="function(){int=clearInterval(int);}"
although obviously better would be to use $.click to bind the event: $('button#foo').click(function(){int=clearInterval(int);}); You will probably also want to check that the onclick function has access to the int variable. If you define 'int' in a particular scope then you need to make sure that the click handler can access the same scope. Without seeing your code then it's difficult to tell. On Aug 21, 10:01 pm, solow <solow.wes...@gmail.com> wrote: > Hey, > > I have a question. > > I want to create a javascript loop, with setInterval(). > This loop has to be used in dynamicaly loaded content, which should be > reloaded every x seconds. This works fine. > > But now, I want to use clearInterval to STOP the interval, when I > leave the dynalically loaded page. Because if I don't, the loop will > keep on running, even when not on that page. So, how do I do this? I > even tried the easiest way, setting a button in the dynamically loaded > content: > > <button onclick="int=window.clearInterval(int)"> > Stop interval</button> > > but this doesn't even work... > > basically, what i want, is to clear all intervals, on a certain div, > when i navigate somehwere else. > > To prevent any confusion, the 'navigate somewhere else' means, other > dynamically content. the page doesn't refresh ever. > > Hope someone can help me. > > Wesley.