Is it possible to append html tags from a content-editable div to another div? I wanted to make an html editor, and I wanted to make automatic preview.
Here is the jsfiddle code: https://jsfiddle.net/eqw8L4to/12/
And here is the js code where I tried getting html tags from .html, and tried appending it to .result:
JavaScript
x
11
11
1
$(document).ready(function() {
2
$(".html").keydown(function(event) {
3
var x = event.keyCode
4
if (x == 27 && event.ctrlKey) {
5
$(".result").html("")
6
var y = $(".html").html()
7
$(".result").append(y)
8
}
9
})
10
})
11
Advertisement
Answer
https://jsfiddle.net/cse_tushar/68na2mrq/8/
Get the text from contenteditable div and replace place in the result HTML
JavaScript
1
10
10
1
$(document).ready(function() {
2
const el = $("div.html");
3
const result = $(".result");
4
el.keydown(function(event) {
5
if (event.keyCode === 27 && event.ctrlKey) {
6
result.html(el.text());
7
}
8
})
9
})
10