I want replace a tag via click function. But right now my whole `@` are getting replaced by my function. I just want to replace last entered `@`. I can find last `@` by using of `lastIndexOf` but the problem is user can entered in between of text. So here come issue, how we know that position of last entered `@`. [Fiddle](http://jsfiddle.net/seuok4r5/3/)

```
<div class="text" contenteditable="true"></div>
<div class="tags">
    <span>tag</span>
        <span>jimmy</span>
        <span>mike</span>
        <span>jonny</span>
</div>

```

JQuery

```
$('.tags span').click(function(){
var html= $('.text').html()
var dd= html.replace('@','<span class="tag">'+$(this).text()+'</span>')
$('.text').html(dd);
})

```