Jquery bbcode append and focus

143 views Asked by At

I am trying to build a BBCode script myself instead of using one from Google :) Better to learn then to just steal/take someone elses work.

I have a problem, when I refresh t page and click on either a smiley or B(bold) it works BUT when I click on the textarea (focus) and then try to click on a smiley or B(bold) it doesnt work :S

Jquery:

<script>
$(document).ready(function() {

$("#emoticons a").click(function (e) {
    e.preventDefault();
    var emoticon = $(this).attr('title');
    $("#bbcode").append(emoticon);
    $("#bbcode").focus();
});

$("div #b").click(function (e) {
    $("#bbcode").appendTo('[b][/b]');
    $("#bbcode").focus();
});

});
</script>

smiley and B(bold):

<a href="#" title=":)"><img src="../img/smileys/smiley.png" border="0" style="cursor:pointer;"/></a>

<div id="b">B</div>

bbcode is the textarea :)

1

There are 1 answers

0
Lewis On

Try this...

 $("#b").on("click",function () {
   $("#bbcode").appendTo('[b][/b]');
   $("#bbcode").focus();
});