I was trying to create a WYSIWYG editor using a contenteditable div. I was trying to bold the selected text using the ExecCommand.This does not seem to work properly . I have tested in IE.Here is the code.Please help me identifying the error if any in the program.
<html>
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"  
     type="text/javascript"></script>                 
    <style>
    #rteToolBar span{
     cursor:pointer;
     }
   #rteToolBar span:hover{
     background:#3535ff;
     }
 </style>
</head>
 <div id="rteWrapper"  >
   <div id="rteToolBar" style="border: thin solid black">
     <span role="BOLD" >B</span>
 <span role="ITAL">I</span>
 <span role="TABL">Table</span>  
   </div>
  <div id="rte" contentEditable="true" style="border: thin solid red">
     asdfla sdf asdf asdfas
 fas <b>fasldf</b> asfdsadf<br/>
 asdfla sdf asdf asdfas
 fas fasldf asfdsadf
</div>
var range,rte,caretoffset;
    $(document).ready(function(){
   var rteWrapper = $('#rteWrapper');
   var toolBar = $('#rteToolBar');
       rte = $('#rte');
   $(toolBar).find('span').live('click',function(){
       rte.focus();
       var _this = $(this);
       var role = _this.attr('role');
            switch(role){
          case 'BOLD': 
          var range1 = document.selection.createRange();
         range1.execCommand('bold',false,null);
          break;
          case 'ITAL': 
          break;
          }
    });
     });
 </script>
 
     
    