0

i have:

                    <tr>
                        <td align="left">Phonenr:</td>
                        <td align="left"><b>
                            <label style="color: #662819;" id="phone">911</label>
                        </b></td>
                        <td><a href="#">Change phone</a></td>
                    </tr>

how can i edit phonenumber after clicking on a href="#" and changing(which way?) label into textfield/box?

r.r
  • 7,023
  • 28
  • 87
  • 129

2 Answers2

1

Based on Change Label to Textbox on edit hyperlink click

Live Demo

$(function() {
  $('a.edit').on("click",function(e) {
    e.preventDefault();
    var dad = $(this).parent().parent();
    var lbl = dad.find('label'); 
    lbl.hide();
    dad.find('input[type="text"]').val(lbl.text()).show().focus();
  });

  $('input[type=text]').focusout(function() {
      var dad = $(this).parent();
      $(this).hide();
      dad.find('label').text(this.value).show();
  });
});
Community
  • 1
  • 1
mplungjan
  • 169,008
  • 28
  • 173
  • 236
0

Try:

$('tr a').click(function() {
    var label = $(this).parent().prev().find('label');
    label.replaceWith('<input type="text" value="211"/>');
    return false;
});

if more then one tr have a tag then you should put id on a or on tr.

jcubic
  • 61,973
  • 54
  • 229
  • 402
  • but i want to edit text freely.. not just 211... everything!! SEE UPDATED QUESTION! – r.r Sep 20 '13 at 20:51
  • If you want to switch back to label then you should keep original label in variable and mabye use detach and append input. – jcubic Sep 20 '13 at 20:54