Change format text selection in div

Angel GX <[email protected]>
Newsgroups gmane.comp.mozilla.devel.dom
Organization http://groups.google.com
Message-ID <afb15709-528d-438e-b987-6905ccf431f3@x35g2000hsb.googlegroups.com>
hi ;)

You forgive my English;)
I speak Spanish.

I want to put it into the selected text in bold tag DIV.
Most do not know how to write the script
Already tried unsuccessfully
------------------------------------------------

<style type="text/css">
.highlighted {
   background-color: yellow;
   color: darkgreen;
   font-weight: bold;
}

</style>

<script>

function decodeIt(textfield) {
strSelection = ""
if (document.selection) {
strSelection = document.selection.createRange().text;
strSelection = strSelection.replace(new RegExp("<","g"), "&lt;");
strSelection = strSelection.replace(new RegExp(">","g"), "&gt;");
document.selection.createRange().text = strSelection;
}
//MOZILLA/NETSCAPE support
else if (textfield.selectionStart || textfield.selectionStart == '0')
{
textfield.focus();
var startPos = textfield.selectionStart;
var endPos = textfield.selectionEnd;
strSelection = textfield.value.substring(startPos, endPos)
alert('hola '+strSelection)
strSelection = strSelection.replace(new RegExp("<","g"), "&lt;");
strSelection = strSelection.replace(new RegExp(">","g"), "&gt;");
textfield.value = textfield.value.substring(0, startPos) +
strSelection + textfield.value.substring(endPos,
textfield.value.length);
}
}

function m(){
element=document.getElementById('n');
sel = window.getSelection();
selectionStart= 2
selectionEnd= 4


   if (typeof document.createRange != 'undefined') {
     var range = document.createRange();
     if (element.firstChild) {
       range.setStart(element.firstChild, startOffset);
       range.setEnd(element.firstChild, endOffset);
       var span = document.createElement('span');
       span.className = 'highlighted';
       range.surroundContents(span);

     }
   }


}
</script>
<input type="button" onclick="decodeIt(document.y.i)" value="Decode
it">
<input type="button" onclick="m()" value="Decode it div">
<form name=y id=y>
<textarea id=i name=i >asoa dald aldada</textarea>
</form>
<div id=n name=n>strSelection asas</div>
--------------------------------------------------------------------------

Thank you for your time ;)

angel matias orozco
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.