I found this line of code and i don't know what it does:
$("body").on("click", "#my_info_box, a.submitSomething", function(){
doSomething();
});
I found this line of code and i don't know what it does:
$("body").on("click", "#my_info_box, a.submitSomething", function(){
doSomething();
});
A delegated-events approach attaches an event handler to only one element, the tbody, and the event only needs to bubble up one level (from the clicked tr to tbody):
$( "#dataTable tbody" ).on( "click", "tr", function() {
alert( $( this ).text() );
});
More found here: http://api.jquery.com/on/
It does event delegation. It means that jQuery will listen for changes inside the #my_info_box
box that might happen with AJAX and will still work on the new data. Otherwise it cannot know new data was loaded with AJAX.
So simply: .on()
is an alternative for .click()
. But it works also for dynamically created elements.