Refresh a jQuery function
Is possible refresh a function every x seconds or refresh it on single event?
I will explain:
I have a function that makes pagination on my website, inside every div that are "pages" I have some pictures where I have added LightBox.
Everything works nice on the first div (page) but when I change the page it doesnt' work anymore.
I tried to fix in this way:
$('.pagination a').click(function () {
initShadow();
});
In this way it work on the pageLoad and on the first page that I change, than it stop again.
So I need to fix this issue, everytime I change the "page" I would like it works fine.
Is possible to refresh a function every x second 开发者_StackOverflow中文版or to refresh it everytime I click on the pagination buttons?
I believe setInterval()
is what you are looking for. If you want to take the timed route.
setInterval(functionToExecute, 1000);
//this would call 'functionToExecute' every 1000 milliseconds
Otherwise, I would recommend using .live()
instead of .click()
just incase your pagination links are being removed and recreated by the plugin. Thought this might be the case when you said it worked 1 additional time after you added this click event.
example
$('.pagination a').live('click',function () {
initShadow();
});
You can use the .on()
method of jQuery.
$(document).on('click', '.pagination a', function () {
initShadow();
});
Hope this helps.
精彩评论