Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  
  
  
  <div class="crazytext" name="msg" id="chatty" contenteditable="true">test</div>
  
  <ul>
    <li><a class="smilepick" href="smile_1"><img src="http://placehold.it/20x20/70f/fff&text=:)" class="emoticon_pick"></a></li>
    <li><a class="smilepick" href="smile_2"><img src="http://placehold.it/20x20/f00/fff&text=:(" class="emoticon_pick"></a></li>
  </ul> 
  
  
</body>
</html>
 
var smilies = { 
  smile_1 : '<img src="http://placehold.it/20x20/70f/fff&text=:)"/>',
  smile_2 : '<img src="http://placehold.it/20x20/f00/fff&text=:("/>'
};
var $chatty = $('#chatty');
$(".smilepick").click(function(event){
   event.preventDefault();
   
   var myHref = $(this).attr('href');
   $chatty.html( $chatty.html()+' '+ smilies[myHref] +' '); 
   var el = $chatty.get(0);
   var elemLen = el.value.length;
   el.selectionStart = elemLen;
   el.selectionEnd = elemLen;
   el.focus();
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
roXonpro
0viewers