0
I’m trying to replace contenteditable
, it replaces but does not play the pointer pro end, always keeps at the beginning. I did not know contenteditable yet and did not find anything 'simple' that works.
The same example in the element input
works properly, but in contenteditable
happens this 'problem' - I don’t know if something is missing...
The idea is to replace a few words and keep the cursor at the typing point.
$(".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>
<div class="elemento" contenteditable="true">
foo bar
</div>
If you want to delegate complexity to something already done, use the library Rangy. It is worth mentioning that it has compatibility for several browsers, including the bad IE.
– Isac