-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLearntoCode.js
25 lines (20 loc) · 935 Bytes
/
LearntoCode.js
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
// Add this to your existing JavaScript code
const runHtmlCodeButton = document.getElementById('runHtmlCode');
const htmlCodeInput = document.getElementById('htmlCode');
const htmlPreview = document.getElementById('htmlPreview');
runHtmlCodeButton.addEventListener('click', runHtmlCode);
function runHtmlCode() {
const code = htmlCodeInput.value;
htmlPreview.innerHTML = code;
}
const applyStylesButton = document.getElementById('applyStyles');
const combinedHtmlCodeInput = document.getElementById('combinedHtmlCode');
const cssCodeInput = document.getElementById('cssCode');
const styledPreview = document.getElementById('styledPreview');
applyStylesButton.addEventListener('click', applyStyles);
function applyStyles() {
const htmlCode = combinedHtmlCodeInput.value;
const cssCode = `<style>${cssCodeInput.value}</style>`;
const combinedCode = cssCode + htmlCode;
styledPreview.srcdoc = combinedCode;
}