Good day.

Guys, tell me, I sit for an hour I can not understand what the problem is.

$('.button').click(function() { $('body').find('form:not(this)').children('label').removeClass('red'); var answer = checkForm($(this).parent().get(0)); if(answer != false) { var result = $(this).siblings('.email').children('input').val(); $('.results').append('<div class="result">'+ result +'</div>'); $('.result').append('<div class="close_btn"></div>') console.log(result); // $('body').remove(); //тут написать, если мейл правильный } }); $('.close_btn').click(function() { $(this).parent('.result').remove(); }); 

The bottom line is that if I write a div with result in html myself and the class close_btn inside it, then everything works fine. But if .result and close_btn are generated by js, it no longer works. What is the problem?

  • Thanks, helped !! - Syaskaa
  • @Alexander Kotov, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Vitalina

1 answer 1

Try writing a push function like this: $('body').on('click', '.close_btn', function() {});