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

**URL:** https://forum.kirupa.com/t/how-to-append-a-space-into-p-activeelement/639403
**Category:** programming
**Created:** [February 13, 2019, 3:29am UTC](https://forum.kirupa.com/t/how-to-append-a-space-into-p-activeelement/639403 "2019-02-13T03:29:52Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)
#### Post date: [February 13, 2019, 3:29am UTC](https://forum.kirupa.com/t/how-to-append-a-space-into-p-activeelement/639403/1 "2019-02-13T03:29:52Z")

</div>

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

```auto
 <p contenteditable="" id="p_tgh">Text Paragraph</p>

```

```javascript
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

---

<div class="post-metadata">

### Author: ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)
#### Post date: [February 13, 2019, 3:49am UTC](https://forum.kirupa.com/t/how-to-append-a-space-into-p-activeelement/639403/2 "2019-02-13T03:49:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)
#### Post date: [February 13, 2019, 5:50am UTC](https://forum.kirupa.com/t/how-to-append-a-space-into-p-activeelement/639403/3 "2019-02-13T05:50:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)
#### Post date: [February 13, 2019, 7:31am UTC](https://forum.kirupa.com/t/how-to-append-a-space-into-p-activeelement/639403/4 "2019-02-13T07:31:06Z")

</div>

Where do you want the 4 spaces to be added?

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

---

<div class="post-metadata">

### Author: ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)
#### Post date: [February 13, 2019, 3:02pm UTC](https://forum.kirupa.com/t/how-to-append-a-space-into-p-activeelement/639403/5 "2019-02-13T15:02:42Z")

</div>

At the end .  
Thanks

---

<div class="post-metadata">

### Author: ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)
#### Post date: [February 13, 2019, 4:43pm UTC](https://forum.kirupa.com/t/how-to-append-a-space-into-p-activeelement/639403/6 "2019-02-13T16:43:11Z")

</div>

I know I can do this sort of thing:

```auto
<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
