var $TextBox = $('#description');
var $Bold = $('#bold');
var $Italic = ('#italic');
var $Underline = ('#underline');
var $Link = ('#link');
var $Menu = $('#menu');
function wrapText(startText, endText){
// Get the text before the selection
var before = $TextBox.val().substring(0, $TextBox.caret().start);
// Get the text after the selection
var after = $TextBox.val().substring($TextBox.caret().end, $TextBox.val().length);
// merge text before the selection, a selection wrapped with inserted text and a text after the selection
$TextBox.val(before + startText + $TextBox.caret().text + endText + after);
// Update the preview
$("#preview").html($TextBox.val());
}
$Bold.on('click', function() {
wrapText("<b>", "</b>");
$Menu.fadeOut("1000");
});
Why my function wrapText does not work?

New Topic/Question
Reply



MultiQuote




|