Adding bdi tag to contenteditable

108 views Asked by At

im trying to add tag to contenteditable when pressing space button in the contenteditable div. problem is its just adding the bdi tag and i cant write inside it, so if i do:

    document.execCommand('insertHTML',false,'<bdi></bdi>)

nothing worked...

i've tried to adding the bdi with innerHTML to contenteditable div but the caret jumping to the start of contenteditable div and i still cant write inside the bdi tag. basically what i try to do is to add bdi tag when pressing space button and write inside it in the current line.

my full code :

<html>
<head>
</head>
<body>
<div id="contenteditablediv" contenteditable="true"></div>
<script language="JavaScript">
var contenteditable = document.getElementById("contenteditablediv");

contenteditable.onkeyup=function(event){
    if (event.keyCode==32) {
        contenteditable.innerHTML+='<bdi><bdi>'
    }
 }

</script>
</body>
</html>
0

There are 0 answers