Jquery Onclick text to text field

css, html, javascript, jquery

Solution

Check this Demo Fiddle

$('#tbl').on('click','.xx',function() {

         var t = $(this).text();
         $(this).text('').append($('<input />',{'value' : t}));
         $('input').focus();


});

$('#tbl').on('blur','input',function() {
    $(this).parent().text($(this).val());
});

Problem

Onclick I want to change the text to input field. If I change the value in the input field and click anywhere, back to text. I found this fiddle. http://jsfiddle.net/davidThomas/767y4/8/ ``` $('#tbl').on('click','.xx',function() { $(this).siblings().each( function(){ if ($(this).find('input').length){ $(this).text($(this).find('input').val()); } else { var t = $(this).text(); $(this).text('').append($('<input />',{'value' : t}).val(t)); } }); }); ``` I used this fiddle. But the input value not changed to text. Please see my updated fiddle. http://jsfiddle.net/5Ach3/ How can to achieve this?

Original source