$('#postLsit').on('click','[id^=save_]', function(event){ var messageId = $(this).attr('id'); messageId = messageId.replace(/save_/g, ''); messageId = parseInt(messageId); var postMessage = tinymce.get(messageId).getContent(); tinymce.execCommand("mceRemoveEditor", true, messageId); var action = 'update'; $.ajax({ url:'action.php', method:"POST", data:{id:messageId, message:postMessage, action:action}, dataType:"json", success:function(data){ var html = $("#postHtml").html(); html = html.replace(/USERNAME/g, data.user); html = html.replace(/POSTDATE/g, data.post_date); html = html.replace(/POSTMESSAGE/g, data.message); html = html.replace(/POSTID/g, data.id); $("#postRow_"+messageId).html(html); $("#editSection_"+messageId).addClass('hidden'); $("#button_section_"+messageId).removeClass('hidden'); } }); });