javascript - Attaching events after DOM manipulation using JQuery ajax -


how attach events after manipulating dom using ajax response. have ajax request html response fragment of html. fragment html have many buttons. want refresh dom declared , attached events applied fragment too. dont want keep on adding each events each button using jquery on(). how else it?

you can use delegated event handling set ahead of time , can made apply newly added dom elements. delegated event handling done .on() , takes form of:

$("static parent selector").on('click', 'selector dynamic element', fn); 

there no clean way run event installing code again , have apply newly added dom elements. have put code in function , code such never adds event handler more once , call function again after adding items dom. or, make function take argument parent object , add event handlers in newly added dom hierarchy.

here's relevant answer delegated event handling: does jquery.on() work elements added after event handler created?


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -