2

I have a contenteditable div:

<div class="r_review_content" contenteditable="true" 
      unselectable="false" style="padding:10px; vertical-align:bottom" ></div>

then I have different smiley images. Now what I am trying to achieve is that when I click on smiley image it should get added at cursor location in above div. This is what I have achieved so far:

  $(".smiley_icon img").click(function(){
        var img_smiley =$(this).clone().css("width","18px");                
        $('.r_review_content').append(img_smiley);          
        return false;   
    });

Demo

Any help will be appreciated.

isherwood
  • 58,414
  • 16
  • 114
  • 157
Kundan Singh
  • 83
  • 10

1 Answers1

-2

Thanks to isherwood for providing me the link to my answer. From there I am using the function given by Tim Down. However I am putting complete answer which could be helpful for any future beginner trying to make emoticons based feedback box.

$(".smiley_icon img").click(function(){
var img_smiley =$(this).clone().css("width","18px").wrap("<div />").parent().html();
$('#r_review_box-100 .r_review_content').focus(); pasteHtmlAtCaret(img_smiley); //adding html at cursorlocation BY - Tim Down return false;
});

Kundan Singh
  • 83
  • 10