This function returns the text that the user has selected and wraps it in tags, in this case bold tags.
function makeBold() {
var selection = window.getSelection();
var range = selection.getRangeAt(0);
var newNode = document.createElement("b");
range.surroundContents(newNode);
}
Now, after calling the function, the selection (selected text) is deleted. How to return this choice, or maybe, how can I name a function without losing my choice in the first place?
source
share