How to replace the pressed character only; Using Javascript/jQuery
<p>Let's say there is textarea with already present text for example: <strong><em>AA</em></strong>. How we can detect the pressed key and change only <em>this</em> character with something else. Now if <strong><em>A</em></strong> key is pressed through keyboard text should become <strong><em>AAB</em></strong> already existing <strong><em>A</em></strong> characters are unaltered but newly pressed <strong><em>A</em></strong> key should write <strong><em>B</em></strong> in textarea.</p>

<p>The code I have is </p>

<pre><code>&lt;textarea&gt;aa&lt;/textarea&gt;

&lt;script&gt;
    jQuery('textarea').keyup(function (e) {
        //THIS REPLACES ALL THE TEXT NOT JUST THE PRESSED CHARACTER
        //Need code that should replace just this pressed key not all text of textarea
        jQuery('textarea').val(jQuery('textarea').val().replace(/a/g, "b"));
    });
&lt;/script&gt;
</code></pre>

<p>Ideal solution will select character from pressed key <code>e</code> and replace it, but if not possible then maybe replacing last character in textarea can be a poor workaround.</p>

<p>Also ok if <code>keypress</code>, <code>keydown</code> or similar event is used.</p>