3
I have the following code:
$('#mais').click(function(){
$('#console').val($('#console').val() +"+");
});
$('#menos').click(function(){
$('#console').val($('#console').val() +"-");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<input id="console" type="text">
<button id="mais">+</button>
<button id="menos">-</button>
In this code I can insert the characters at the end of the input whenever I click on the corresponding buttons, but how do I insert in the last position of the text cursor inside the input?
Example:
- I typed the text:
- I placed the text cursor in the middle of the text:
- I clicked the button -, I would like the result to be this:
maismais
mais|mais
mais-mais
While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed. - Of Revision
– NoobSaibot
I edited the answer.
– Vitor E.C.
To get better I’d have to explain your answer ?
– NoobSaibot