Why not working jQuery function for loadable content ?

Hello.

There is a function to output the table via AJAX
$(function() {
$('#getShelving').click(function(){
$.ajax({
 url: "ajax/echoShelving.php",
 cache: false,
 success: function(html){
$("#resultshelvingAdd").html(html);
}
});
$.ajax({
 url: "ajax/echoStorageOption.php",
 cache: false,
 success: function(html){
$("#resultechoCtorageOption").html(html);
}
});
});
});


and the function of deleting these lines

$(function() {
$('.delShelving').on('click', function() {
 if(confirm("are You sure you want to delete?")) {
$('#load').fadeIn();
$(this).parent();
 var id = $(this).attr("id");
 $.post("ajax/delShelving.php",{id : id},AjaxSuccess);
 $(this).parent().slideUp('slow', function() {$(this).remove();});
 // Display mail message about the successful deletion of the row
 function AjaxSuccess(data)
{
alert("Removed");
//$('#otvet').html(data);
}
 return false;
}
});
});


the problem is that after the withdrawal of the table a function to delete rows not working
September 26th 19 at 06:08
2 answers
September 26th 19 at 06:10
$('.delShelving').on('click', function() {
// change to 
$(document).on('click', '.delShelving', function() {

and try. Must now earn.

And then go to Google, and from there get on the jQuery site at the stranik method .on() and read what is Direct and delegated events and how they Ballada (bubble) up the DOM tree.
add that the author forgot after work $(document), and he will understand what is delegation, replace the document on the nearest parent that is not added dynamically. - tanner_Wintheis commented on September 26th 19 at 06:13
there is no difference at what stage will fulfill a handler, a couple of microseconds do not play a role. - jaclyn commented on September 26th 19 at 06:16
well, I'm not a supporter of pennies to count, nevertheless.
and You actually what happened? The answer You wrote. - tanner_Wintheis commented on September 26th 19 at 06:19
September 26th 19 at 06:12
Read about direct and delegated the processing, use

$('parent').on('click', 'child', function(){ //... });
// parent is the closest parent that is not added dynamically
// child — Your item that You put in a click event, ie '.delShelving'

Find more questions by tags JavaScriptjQuery