title: How to edit and update values in a dynamic table using JQuery?
body: <p>Below is code for adding inputs into a dynamic table and for each row an edit button is also generated, my question is how would I pass the values in the table back into the input fields when I click on the edit button of a specific row and then update the specific row based on the changes made to the values in the input fields when i click on the update row button. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$("#btnAdd").on('click', function() {
    let row = '&lt;tr&gt; &lt;td&gt;' + $("#insert-name").val() + '&lt;/td&gt; &lt;td&gt;' + $("#insert-surname").val() + '&lt;/td&gt; &lt;td&gt;' + "edit" + '&lt;/td&gt; &lt;/tr&gt;'
    $('tbody').append(row);
  
    $('td:contains("edit")').html("&lt;button type='button'&gt;" + "edit" + "&lt;/button&gt;").on('click', function() {
  
    });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;form&gt;
    &lt;div&gt;
      &lt;label for="insert-name"&gt;Name:&lt;/label&gt;
      &lt;input type="text" id="insert-name"&gt;
    &lt;/div&gt;
    &lt;div&gt;
      &lt;label for="insert-surname"&gt;Surname:&lt;/label&gt;
      &lt;input type="text" id="insert-surname"&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  
  &lt;button type="button" id="btnAdd"&gt;Add to Table&lt;/button&gt;
  &lt;button type="button" id="btnUpdate"&gt;Update row&lt;/button&gt;
  
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th scope="col"&gt;Name&lt;/th&gt;
        &lt;th scope="col"&gt;Surname&lt;/th&gt;
        &lt;th scope="col"&gt;Edit&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody id="tbody"&gt;&lt;/tbody&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>