0
deletes.forEach(element => { // foreach button 'delete' adds event Listener (this function not working with new created elements)
    element.addEventListener('click', () => {
        e.preventDefault()
        axios.get(`./includes/get_post.php?delete=${element.id}`).then(response => {tableData.innerHTML = response.data;}) // innerHtml creates new 'delete' buttons
    })

I tried do do it with recursion but its not working upd. Added HTML content:

<tbody>
     <?php 
    $users = mysqli_query($connection,"SELECT * FROM `users` ORDER BY `id` ");
 ?>
   <?php
      while($user = mysqli_fetch_assoc($users)){
   ?>
   <a id="<?php echo $user['id'] ?>" data-toggle="modal" data-target="#ModalConfirm" class="table-link danger delete-item">
     <span class="fa-stack">
    <i class="fa fa-square fa-stack-2x"></i>
   <i class="fa fa-trash-o fa-stack-1x fa-inverse del"></i>
  </span>
  </a>
<?php
 }
 ?>

(sorry for the format )

  • Does this answer your question? [Event binding on dynamically created elements?](https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) – Emiel Zuurbier Nov 03 '20 at 13:49
  • Absolutely no, sorry – Ivan Komarnytskiy Nov 03 '20 at 13:51
  • The answer to your issue is *event delegation*. Create a single event handler which listens for the click event in all children. Could you add your HTML concerning the content that is dynamically changed? – Emiel Zuurbier Nov 03 '20 at 13:57

0 Answers0