I'm trying to give a replace in contenteditable
, it replaces but does not throw the pointer to the end, it always keeps on startup. I did not know contenteditable yet and found nothing 'simple' that works.
The same example in element input
works correctly, but in contenteditable
this problem happens - I do not know if something is missing ...
The idea is to replace some words and keep the cursor at the point of typing.
$(".elemento").on('input', function( e )
{
content = $(this).html().replace(/foo/g, 'bar');
$(this).html( content )
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="elemento" contenteditable="true">
foo bar
</div>