JSFiddle - React, Tailwind, and code Playground
by cory a
HTML
<div id="selectme"></div>
<p>Click me!</p>
JavaScript
jQuery.fn.selectText = function(){
var doc = document
, element = this[0]
, range, selection
;
if (doc.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
};
$(function() {
$('#selectme').on('click', '.replace', function() {
$(this).selectText();
});
});
$("#selectme").html("<span class='replace'>Some text goes here!</span><span class='replace'>More text!</span>")