There are way better ways to use this function, one is a rich text editing...
Here is a small rich text editor I wrote in 5mins.... You can take a look at it...
Code:
<html>
<head>
<title>RichText using contentEditable</title>
<style type="text/css">
#richTextBox {
width:500px;
height:200px;
overflow:scroll;
border:1px solid black;
padding:5px;
}
</style>
<script language="javascript" type="text/javascript">
function rtbFormat(command, value) {
document.getElementById("richTextBox").focus();
document.execCommand(command, false, value);
}
</script>
</head>
<body>
<input type="button" name="boldText" onclick="rtbFormat('Bold', '');" value="Bold" />
<input type="button" name="fontName" onclick="rtbFormat('FontName', 'Georgia');" value="Font: Georgia" />
<input type="button" name="fontSize" onclick="rtbFormat('FontSize', 22);" value="Font: 22" />
<input type="button" name="textAlign" onclick="rtbFormat('JustifyCenter', '');" value="Center Text" />
<div id="richTextBox" contenteditable></div>
</body>
</html>
And here a little preview:
It's just that the use of the function you're showing is simply pointless and not needed.