JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://ynternet.sk/jq/jquery_ui/js/jquery-ui-1.8.24.custom.min.js"></script>
<link rel="stylesheet" href="http://ynternet.sk/jq/jquery_ui/css/ui-lightness/jquery-ui-1.8.24.custom.css">
<div id="add" style="background:yellow; width:100px;">add new</div>
<div id="container"></div>
<br>
CSS
#container {
width:500px;
height:500px;
background: palegoldenrod;
position: relative;
top:20px;
left: 100px;
padding: 0px;
}
.add_to_this {
background:yellowgreen;
position: absolute;
display:inline-block;
width:200px;
height:50px;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
-o-user-select: none;
}
JavaScript
function handler4() {
var edited_DIV = $(this);
if ($(this).children('textarea').length === 0) {
var text_from_DIV = $(edited_DIV).find("#edit_div").clone().children().remove().end().text();
var menu = $(this).find("#edit_div").find('#menu');
$(this).find("#edit_div").text('').append(menu).append("<textarea class='inputbox' >" + text_from_DIV + "</textarea>");
$("textarea.inputbox").focus();
$("textarea.inputbox").blur(function () {
var text_from_TEXTAREA = $(this).val();
$(edited_DIV).find("#edit_div").text(text_from_TEXTAREA).prepend(menu);
});
}
}
$("#add").on({
click: function (e) {
var timestamp = Date.now();
var posx = Math.floor(Math.random() * 400);
var posy = Math.floor(Math.random() * 400);
$('#container').append(function () {
return $('<div class="add_to_this" id="' + timestamp + '" style="left:' + posx + 'px; top:' + posx + 'px; "><div id="edit_div"><div id="menu" style="color:red;"><b> MENU </b></div>Click here to edit</div></div>').dblclick(handler4).draggable({
containment: "#container",
scroll: false,
cursor: 'lock',
opacity: 0.55,
grid: [2, 2]
}).resizable();
});
}
});