Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72388

Move Cursor Backwards One Character jQuery [duplicate]

$
0
0

I am making a text editing document and I have a function which automatically places ")" when the user types "(". However this places the cursor outside of the closing bracket. So I would like to move the cursor back one character so that the user can type within the brackets. This is my current code:

<body>
    <textarea name="input" id="input" cols="30" rows="10"></textarea>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
        $("#input").on("keyup", function(e) {
            if (e.which == 57) {
                $("#input").focus();
                // and just run the command
                document.execCommand('insertText', false /*no UI*/ , ")");
            }
        });
    </script>

</body>

What is the simplest way to accomplish this?


Viewing all articles
Browse latest Browse all 72388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>