JSFiddle - React, Tailwind, and code Playground
by Christian Gambardella
HTML
<div class="editable" contenteditable="true">some test text</div><br>
<input type="button" name="bold" value="bold">
<input type="button" name="italic" value="italic">
<input type="button" name="createlink" value="createlink">
<input type="button" name="unlink" value="unlink">
CSS
.editable {
padding: 10px;
border: 1px solid grey;
}
JavaScript
$('input[type="button"]').click(function() {
var cmd = $(this).attr("name");
//var createLink = function(cmd) {
// document.execCommand(cmd, "", "http://www.google.de");
//};
switch (cmd) {
case "createlink":
var url = prompt("Please type in the url", "URL");
document.execCommand(cmd, "", url);
//createLink(cmd);
break;
default:
document.execCommand(cmd, "", null);
break;
}
});