Saturday, 15 January 2011

pagination - create jquery .click before elements exists -



pagination - create jquery .click before elements exists -

this question has reply here:

in jquery, how attach events dynamic html elements? [duplicate] 9 answers

i have jquery function list of links ( <a href="#" class="paging">1</a> ) create $(".paging").click(.... problem phone call jquery script.js on main php file, while links create on later stage.

how reparse javascript file? there way that, maybe create jquery click function every time create links?

you need utilize event delegation:

event delegation allows attach single event listener, parent element, fire descendants matching selector, whether descendants exist or added in future.

$("body").on('click','.paging',function(){ //code here });

note: best practice utilize closest parent (instead of body selector in above case) exists origin , not alter in future.

jquery pagination

No comments:

Post a Comment