forked from AnujShrivastava01/AnimateItNow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.js
More file actions
39 lines (34 loc) · 977 Bytes
/
editor.js
File metadata and controls
39 lines (34 loc) · 977 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
26
27
28
29
30
31
32
33
34
35
36
37
38
const htmlEditor = document.getElementById("htmlCode");
const cssEditor = document.getElementById("cssCode");
const jsEditor = document.getElementById("jsCode");
const output = document.getElementById("output");
document.getElementById("runBtn").addEventListener("click", () => {
const html = htmlEditor.value.trim();
const css = cssEditor.value.trim();
const js = jsEditor.value.trim();
const result = `
<!DOCTYPE html>
<html lang="en">
<head>
<style>${css}</style>
</head>
<body>
${html}
<script>
try {
${js}
} catch (e) {
document.body.innerHTML += '<pre style="color:red;">' + e + '</pre>';
}
<\/script>
</body>
</html>
`;
output.srcdoc = result;
});
document.getElementById("resetBtn").addEventListener("click", () => {
htmlEditor.value = "";
cssEditor.value = "";
jsEditor.value = "";
output.srcdoc = "<!DOCTYPE html><html><body></body></html>";
});