JSFiddle - React, Tailwind, and code Playground
HTML
<div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
<p>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
CSS
textarea {
width: 90%;
height: 150px;
}
.split-but {
position: absolute;
right: 0;
bottom: -23px;
padding: 3px 10px;
background: #ed7700;
color: #fff;
font-size: 12px;
text-transform: uppercase;
border-radius: 0 0 3px 3px;
}
div,
textarea {
border: 1px solid #00F;
position: relative;
margin: 10px;
padding: 10px;
}
JavaScript
$('div, textarea').on('click', function(e) {
//$('textarea').getCursorPosition();
var $splitbut = $('<p class="split-but">Split</p>').on('click', splitdiv);
var el = $(this).get(0);
var pos = 0;
var userSelection;
if (window.getSelection) {
userSelection = window.getSelection();
}
var start = userSelection.anchorOffset;
var end = userSelection.focusOffset;
console.log(pos);
var before = $(this).html().substr(0, start);
var after = $(this).html().substr(start, $(this).html().length);
console.log(after);
});
var splitdiv = function(e) {
e.stopPropagation();
console.log('a');
};