JSFiddle - React, Tailwind, and code Playground
by zono
HTML
<div id="elementId">123456</div>
JavaScript
function applyOperation(element, op) {
if(typeof op['insert'] != 'undefined' && typeof op['pos'] != 'undefined') {
var resultHtml = element.html().replace(new RegExp("((?:[^\s]|[\s]+){" + op['pos'] + "})"), "$1" + op['insert']);
element.html(resultHtml);
return element;
}
}
applyOperation($("#elementId"), {insert: 'This works', pos:2});