I am in need of creating a new element at the end of another element. For instance, let's say I have this element:
<div id="elmtobetrig">Element that should be followed by another element when the user hits enter after this text. <!--Element placeholder--></div>
I have tried the following code:
<div contenteditable="true" id="elmtobetrig"></div>
<script>document.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
document.querySelector("div#elmtobetrig").createElement("line").innerHTML = "<br> This content should appear at the bottom of the element "
}
});</script>
However, it seems that using createElement()
on a specific element is not possible... Is there an alternative way to achieve what I am attempting?