How to append a space into <p> 'activeElement' ?

Hello & Thanks,
Sorry , I can’t get the three ticks working .
(windows pc) Is it three quote marks or what ?
I have this paragraph :

 <p contenteditable="" id="p_tgh">Text Paragraph</p>
window.addEventListener("keydown", onPress_ENTER, false);
// Which I don't allow the 'enterkey' to be pressed

function onPress_ENTER(event){
    var keyPressed = event.keyCode || event.which;
    //if ENTER is pressed
    if(keyPressed==13)
    {
    // Good here: 
        event.preventDefault();
        stopImmediatePropagation();
    // Do stuff here too:
    }
    else
    {
        return false;
    }
}

Which works fine .
Since that

has focus I now want to insert a space ,
or actually 4 spaces " " .
Pls, how can this be done ?
Thanks

The paragraph:
<p>contenteditable="" id="p_tgh" Text Paragraph </p>
Ah there it is ‘backwards tick’ :sleeping:
Thanks

I edited your post to add the right formatting. :madscientist:

Where do you want the 4 spaces to be added?

  • At the beginning?
  • At the end?
  • At the current position of the caret?

At the end .
Thanks

I know I can do this sort of thing:

<script>
var  someDots = "....";
var origContents = "";
var newContents = "";
function myFunction() {

  origContents = document.getElementById("demo").innerHTML ; 
  newContents = origContents + someDots; 
  document.getElementById("demo").innerHTML = newContents; 
}
</script>

But how do I determine which element was clicked ,
because there will be many paragraphs and the number of paragraphs changes dynamically ; and each paragraph won’t have an “id=” .
Thanks