Can you please tell me how to hide the element ( message ) by clicking on another element ( q-delete-icon )? Currently this code:

 $(function() { $('.q-delete-icon').click(function(){ $('.message').click(function(){ $(this).hide('slow'); }); }); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class='message'> <div class='q-delete-icon' id='2'>close</div> От кого:<a href='#'>Ttt</a> | <br /> 2013-07-23 19:31:44<br /> Сообщение </div> 

  • HTML structure show. And what's the use of ajax in tags? Maybe jQuery? - Deonis
  • Yes, jquery. It is necessary that the message element hides exactly the one that was clicked on q-delete-icon. The first time everything is as it should, the second time the message is already hidden even if you do not click on q-delete-icon. HTML: <div class = 'message'> <div class = 'q-delete-icon' id = '2'> </ div> From: <a href='#'> Ttt </a> | <br /> 2013-07-23 19:31:44 <br /> Message </ div> - tayler882

1 answer 1

 $('.q-delete-icon').click(function(){ $(this).closest('.message').hide('slow'); }); 

Demo: http://jsfiddle.net/XahXU/