I have a monospaced text area (unlike the stackexchange editor). When my user clicks, I need a character that is automatically displayed in the previous line using jQuery. I know what I need to use .click()to bind a function to this event, but the logic of the function eludes me.
Desired behavior ... user clicks on asterisk *
Here is some text in my editor.
When I double click at a position*
I want to insert a new line above, with a new character at the same position
The above text should be next after the function starts
Here is some text in my editor.
*
When I double click at a position*
I want to insert a new blank line above, at the same position
What I tried:
I found a jQuery carriage plugin that has a function called caret()that I can find to find the position of the asterisk when I click (position 74).
<script src='jquery.caret.js'></script>
$('textarea').click(function(e) {
if (e.altKey){
alert($("textarea").caret());
}
});
, . .