You can do the following:
Have a click event and create a text field on the fly that takes the text in the div as a value.
They even have a blur that binds to this text field and makes an AJAX call and if successful changes the text div
Lets say your HTML is like:
<div id="fullname">Amazing Spider man</div>
And your JS code will look like this:
$('#fullname').click(function(){ var name = $(this).text(); $(this).html(''); $('<input></input>') .attr({ 'type': 'text', 'name': 'fname', 'id': 'txt_fullname', 'size': '30', 'value': name }) .appendTo('#fullname'); $('#txt_fullname').focus(); }); $(document).on('blur','#txt_fullname', function(){ var name = $(this).val(); $.ajax({ type: 'post', url: 'change-name.xhr?name=' + name, success: function(){ $('#fullname').text(name); } }); });
This is demonstrated in this jsfiddle.
source share