<b id="info">тут есть текст</b> $('.show').on('click', function() { $.ajax({ type: "post", url: '123', success: function(data) { var json = JSON.parse(data); $('#info').html(json.text+'<button type="button" class="btn btn-success check">кнопка</button>'); } }); }) $('.check').on('click', function() { $.ajax({ type: "post", url: '123', success: function(data) { var json = JSON.parse(data); if(json.check == 'ok'){ location.reload(); } } }); }) 

I can not figure out why when adding a button to a page, in the future it does not want to work

1 answer 1

For dynamic elements, delegated event handling is used, looks like this:

 $('parent').on('event', 'children', function(e){ //Какое-то действие }); 

Where parent is a static parent element, event is an event, children is a child dynamic element on which the handler should work.