In the example below, entering HTML into the contenteditable
div should render as HTML inside #html_view
, but instead of rendering as HTML it is rendering as text.
For example: when entering the following HTML, it should render "sometext" inside a red container but the string is transferred as is.
<p style="background-color:red;">sometext</p>
How can I render the content of a contenteditable
div as HTML inside another element?
function move_to_the_other_div(el){
document.getElementById('html_view').innerHTML = el.innerHTML;
}
#html_view{
width:300px;
overflow:hidden;
border:1px solid gray;
padding:10px;
min-height:50px;
}
#code_view{
width:300px;
border:1px solid gray;
padding:10px;
min-height:50px;
font-size:18px;
}
<div id="html_view"></div>
<div contenteditable id="code_view" oninput="move_to_the_other_div(this);" onpaste="move_to_the_other_div(this);"></div>