I want to change a label into a textbox when the user clicks on the EDIT link. I am doing the same thing that is discussed in this post, only difference is that I am using mvc razor syntax DisplayFor
instead of using <label class="text-info">Saghir</label>
.
I am not getting the desired result, please tell me where I am going wrong.
HTML:
@Html.DisplayFor(m => m.FirstName, new { @id = "#attribute", @class = "text-info" })
<a href="#" id="edit">Edit</a>
JS:
<script>
$('#edit').click(function () {
var text = $('.text-info').text();
var input = $('<input id="attribute" type="text" value="' + text + '" />')
$('.text-info').text('').append(input);
input.select();
input.blur(function () {
var text = $('#attribute').val();
$('#attribute').parent().text(text);
$('#attribute').remove();
});
});
</script>