JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://benalman.com/code/projects/jquery-outside-events/jquery.ba-outside-events.js"></script>
<table><tr><td class="inline-edit">
<span>abcdpqsdfsdfsdfrstuvwxyz<?php echo $i?></span>
<img id="pencil_edit" src="http://placehold.it/20"/>
</td></tr></table>
JavaScript
$('.inline-edit').on('click', function(ev) {
var td = $(this);
if (!td.find(':input').length) {
var current_val = td.find('span').html();
td.html('<input type="text" class="txt" maxlength="27" value="' + current_val + '"/>');
//On outside click, cancel
td.unbind('clickoutside').bind('clickoutside', function(event) {
cancelEdit(td, current_val);
})
}
ev.stopPropagation();
});
function cancelEdit(element, value) {
$(element).html('<span>' + value + '</span><img id="pencil_edit" src="http://placehold.it/20">');
}