title: Dynamic table JS
body: <p>I already have php code written all right, through Ajax requests go. when I click on edit, it appears in the input line, I enter the data, they are sent to the server, but this input is not deleted. The row of the table should return to the initial state, but already with the changed data. The same problem with deleting a row, when you click on delete, data is deleted from the database, but nothing happens in the frontend.
  Link with code <a href="https://codepen.io/alekspvn/pen/EwwwrZ" rel="nofollow noreferrer">https://codepen.io/alekspvn/pen/EwwwrZ</a>    sorry for php code here)
  if there is unreadable, then I input the code here</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;table align="center" cellpadding="10" border="1" id="user_table"&gt;
  &lt;tr&gt;
  &lt;th&gt;Title&lt;/th&gt;
  &lt;th&gt;Anonce&lt;/th&gt;
  &lt;th&gt;Url&lt;/th&gt;
  &lt;th&gt;Action&lt;/th&gt;
  &lt;/tr&gt;
  &lt;?php
   foreach($eq_arr as $row):
   ?&gt; 
  
    &lt;tr id="row&lt;?php echo $row-&gt;id;?&gt;"&gt;
    &lt;td id="title_val&lt;?php echo $row-&gt;id;?&gt;"&gt;&lt;?php echo $row-&gt;title;?&gt;&lt;/td&gt;
    &lt;td id="anonce_val&lt;?php echo $row-&gt;id;?&gt;"&gt;&lt;?php echo $row-&gt;anonce;?&gt;&lt;/td&gt;
    &lt;td id="url_val&lt;?php echo $row-&gt;id;?&gt;"&gt;&lt;?php echo $row-&gt;url;?&gt;&lt;/td&gt;
    &lt;td&gt;
     &lt;input type='button' class="edit_button" id="edit_button&lt;?php echo $row-&gt;id;?&gt;" value="edit" onclick="edit_row('&lt;?php echo $row-&gt;id;?&gt;');"&gt;
     &lt;input type='button' class="save_button" id="save_button&lt;?php echo $row-&gt;id;?&gt;" value="save" onclick="save_row('&lt;?php echo $row-&gt;id;?&gt;');"&gt;
     &lt;input type='button' class="delete_button" id="delete_button&lt;?php echo $row-&gt;id;?&gt;" value="delete" onclick="delete_row('&lt;?php echo $row-&gt;id;?&gt;');"&gt;
    &lt;/td&gt;
   &lt;/tr&gt;
   &lt;?php
  endforeach;
  ?&gt;
  
  &lt;tr id="new_row"&gt;
   &lt;td&gt;&lt;input type="text" id="new_title"&gt;&lt;/td&gt;
   &lt;td&gt;&lt;input type="text" id="new_anonce"&gt;&lt;/td&gt;
   &lt;td&gt;&lt;input type="text" id="new_url"&gt;&lt;/td&gt;
   &lt;td&gt;&lt;input type="button" value="Insert Row" onclick="insert_row();"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;/table&gt;
  </code></pre>
  
  <p>JS</p>
  
  <pre><code>function edit_row(id)
  {
   var title=document.getElementById("title_val"+id).innerHTML;
   var anonce=document.getElementById("anonce_val"+id).innerHTML;
   var url=document.getElementById("url_val"+id).innerHTML;
  
   document.getElementById("title_val"+id).innerHTML="&lt;input type='text' id='title_text"+id+"' value='"+title+"'&gt;";
   document.getElementById("anonce_val"+id).innerHTML="&lt;input type='text' id='anonce_text"+id+"' value='"+anonce+"'&gt;";
   document.getElementById("url_val"+id).innerHTML="&lt;input type='text' id='url_text"+id+"' value='"+url+"'&gt;";
  
   document.getElementById("edit_button"+id).style.display="none";
   document.getElementById("save_button"+id).style.display="block";
  }
  
  function save_row(id)
  {
   var title=document.getElementById("title_text"+id).value;
   var anonce=document.getElementById("anonce_text"+id).value;
   var url=document.getElementById("url_text"+id).value;
  
   jQuery.ajax
   ({
    type:'post',
    url:'../wp-content/plugins/related-equipment/update.php',
    data:{
     edit_row:'edit_row',
     row_id:id,
     title_val:title,
     anonce_val:anonce,
     url_val:url
    },
    success:function(response) {
     if(response=="success")
     {
      document.getElementById("title_val"+id).innerHTML=title;
      document.getElementById("anonce_val"+id).innerHTML=anonce;
      document.getElementById("url_val"+id).innerHTML=url;
      document.getElementById("edit_button"+id).style.display="block";
      document.getElementById("save_button"+id).style.display="none";
     }
    }
   });
  }
  
  function delete_row(id)
  {
   jQuery.ajax
   ({
    type:'post',
    url:'../wp-content/plugins/related-equipment/update.php',
    data:{
     delete_row:'delete_row',
     row_id:id,
    },
    success:function(response) {
     if(response=="success")
     {
      var row=document.getElementById("row"+id);
      row.parentNode.removeChild(row);
     }
    }
   });
  }
  
  function insert_row()
  {
   var title=document.getElementById("new_title").value;
   var anonce=document.getElementById("new_anonce").value;
   var url=document.getElementById("new_url").value;
  
   jQuery.ajax
   ({
    type:'post',
    url:'../wp-content/plugins/related-equipment/update.php',
    data:{
     insert_row:'insert_row',
     title_val:title,
     anonce_val:anonce,
     url_val:url
    },
    success:function(response) {
     if(response!="")
     {
      var id=response;
      var table=document.getElementById("user_table");
      var table_len=(table.rows.length)-1;
      var row = table.insertRow(table_len).outerHTML="&lt;tr id='row"+id+"'&gt;&lt;td id='title_val"+id+"'&gt;"+title+"&lt;/td&gt;&lt;td id='anonce_val"+id+"'&gt;"+anonce+"&lt;/td&gt;&lt;td id='url_val"+id+"'&gt;"+url+"&lt;/td&gt;&lt;td&gt;&lt;input type='button' class='edit_button' id='edit_button"+id+"' value='edit' onclick='edit_row("+id+");'/&gt;&lt;input type='button' class='save_button' id='save_button"+id+"' value='save' onclick='save_row("+id+");'/&gt;&lt;input type='button' class='delete_button' id='delete_button"+id+"' value='delete' onclick='delete_row("+id+");'/&gt;&lt;/td&gt;&lt;/tr&gt;";
      document.getElementById("new_title").value="";
      document.getElementById("new_anonce").value="";
      document.getElementById("new_url").value="";
     }
    }
   });
  }
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>global $wpdb;
  $table_name = $wpdb-&gt;prefix . 'rel_eq';
  if ( isset( $_POST['edit_row'] ) ){
      $wpdb-&gt;update( $table_name, array(
          'id'=&gt;$_POST['row_id'],
          'title' =&gt; $_POST['title_val'], 
          'anonce' =&gt; $_POST['anonce_val'],
          'url' =&gt; $_POST['url_val']),
  
      array( 'id' =&gt; $_POST['row_id'] ),
          array( '%s', '%s', '%s', '%s') 
      );
       echo mysql_insert_id();
       exit();
  }
  
  if ( isset( $_POST['insert_row'] ) ){
      $wpdb-&gt;insert( $table_name, array(
          'id'=&gt;$_POST['row_id'],
          'title' =&gt; $_POST['title_val'], 
          'anonce' =&gt; $_POST['anonce_val'],
          'url' =&gt; $_POST['url_val']),
          array( '%s', '%s', '%s', '%s') 
      );
       echo mysql_insert_id();
       exit();
  }
  
  if ( isset( $_POST['delete_row'] ) ){
      $wpdb-&gt;delete( $table_name, array(
          'id'=&gt;$_POST['row_id']),
          array( '%s') 
      );
       echo mysql_insert_id();
       exit();
  }
  </code></pre>