-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (26 loc) · 1.17 KB
/
script.js
File metadata and controls
34 lines (26 loc) · 1.17 KB
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
const tabLinks = document.querySelectorAll(".tab-link");
const codeEditors = document.querySelectorAll(".code-editor");
tabLinks.forEach(tab => {
tab.addEventListener("click", () => {
const target = document.querySelector(tab.dataset.tabTarget);
codeEditors.forEach(editor => editor.classList.remove("active"));
tabLinks.forEach(tab => tab.classList.remove("active"));
tab.classList.add("active");
target.classList.add("active");
console.log("Switched to tab: ", tab.textContent);
});
});
const htmlEditor = document.getElementById("htmlEditor");
const cssEditor = document.getElementById("cssEditor");
const jsEditor = document.getElementById("jsEditor");
const output = document.getElementById("code-output");
function updateOutput() {
const htmlCode = htmlEditor.value;
const cssCode = `<style>${cssEditor.value}</style>`;
const jsCode = `<script>${jsEditor.value}<\/script>`;
output.srcdoc = htmlCode + cssCode + jsCode;
console.log("Output updated!");
}
htmlEditor.addEventListener("input", updateOutput);
cssEditor.addEventListener("input", updateOutput);
jsEditor.addEventListener("input", updateOutput);