Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 or to refresh it everytime I click on the pagination buttons?

like image 316
Andrea Turri Avatar asked Dec 10 '25 03:12

Andrea Turri


1 Answers

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();
});
like image 172
jondavidjohn Avatar answered Dec 12 '25 18:12

jondavidjohn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!