Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that the <strong>first handler is the only one attached</strong> in script.</p> <p>Your javascript code is executed when the page is ready.<br> At that moment only the first handler is attached because there is not yet an element <code>button#save-email</code>. When you click save, it is the <strong>first</strong> handler that is executed again, not the one think !</p> <p>Why don't you create two distinct buttons and show one or the other ?</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td class="email"&gt;myemail@domain.com&lt;/td&gt; &lt;td&gt; &lt;button class="btn-edit"&gt;Edit&lt;/button&gt; &lt;button class="btn-save" style="display:none"&gt;Save&lt;/button&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="email"&gt;myemail@domain.com&lt;/td&gt; &lt;td&gt; &lt;button class="btn-edit"&gt;Edit&lt;/button&gt; &lt;button class="btn-save" style="display:none"&gt;Save&lt;/button&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>Javascript</p> <pre><code>// listen for email edit button click $('.btn-edit').on('click', function() { var $this = $(this), $parentRow = $this.closest('tr'); // get email inline to this edit button var email = $this.parent().siblings('td.email').html(); // change button from edit to save $parentRow.find('.btn-edit').hide(); $parentRow.find('.btn-save').show(); // change email display to input field $(this) .parent() .siblings('td.email') .html('&lt;input type="text" id="user-email" value="'+email+'" /&gt;'); }); // listen for email save button click $('.btn-save').on('click', function() { var $this = $(this), $parentRow = $this.closest('tr'); // get new email inline to this save button var newEmail = $(this).parent().siblings('td.email').find('#user-email').val(); // change input field back to display $(this).parent().siblings('td.email').html(newEmail); // change button from save to edit $parentRow.find('.btn-edit').show(); $parentRow.find('.btn-save').hide(); }); </code></pre> <p><strong><a href="http://jsfiddle.net/didierg/bTr6d/" rel="nofollow">DEMO</a></strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload