-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
25 lines (21 loc) · 770 Bytes
/
Copy pathscript.js
File metadata and controls
25 lines (21 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const htmlCode = document.getElementById("html-code");
const cssCode = document.getElementById("css-code");
const jsCode = document.getElementById("js-code");
const output = document.getElementById("output");
function runCode() {
const html = htmlCode.value;
const css = `<style>${cssCode.value}</style>`;
const js = jsCode.value;
const iframeDoc = output.contentDocument || output.contentWindow.document;
iframeDoc.open();
iframeDoc.write(html + css);
iframeDoc.close();
try {
output.contentWindow.eval(js);
} catch (error) {
console.error(error);
}
}
htmlCode.addEventListener("keyup", runCode);
cssCode.addEventListener("keyup", runCode);
jsCode.addEventListener("keyup", runCode);