Every time you click the .text
element, you are rebinding the .text_submit
handler. There are a lot of different ways of going about solving this. Here's something I hacked together quickly using deferred. There's plenty of room for improvement:
$('.text').click(function () {
var clicked = this;
getText().done(function (result) {
console.log(this);
$(clicked).siblings('div.text_container').html(result);
});
});
function getText() {
var def = $.Deferred();
$('.text_edit').removeAttr('style');
$('.text_edit').dialog({
width: 300,
height: 150,
maxWidth: 300,
maxHeight: 150,
minWidth: 300,
minHeight: 150,
buttons: [{
text: "Submit",
click: function () {
def.resolve($('textarea#texto').val());
$(this).dialog('close');
}
}]
});
return def.promise();
}