{ "$schema": "../schemas/code-crispies-module-schema.json", "id": "js-dom", "title": "JS DOM", "description": "Learn to select HTML elements with querySelector, change their text content, and modify their styles using JavaScript.", "mode": "javascript", "difficulty": "beginner", "lessons": [ { "id": "js-query", "title": "Select an Element", "description": "Use document.querySelector() to find an element by its CSS selector. It returns the first matching element.", "task": "Select the element with id box and store it in a const el", "previewHTML": "
", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; }", "sandboxCSS": "", "initialCode": "", "solution": "const el = document.querySelector(\"#box\");", "codePrefix": "", "codeSuffix": "\nif (el) el.textContent = \"Found!\";", "previewContainer": "preview-area", "validations": [ { "type": "contains", "value": "querySelector", "message": "Use document.querySelector() to select the element" }, { "type": "regex", "value": "querySelector\\s*\\([\"']#box[\"']\\)", "message": "Pass \"#box\" as the selector" }, { "type": "regex", "value": "const\\s+el\\s*=", "message": "Store the result in a constant named el" } ] }, { "id": "js-text", "title": "Change Text", "description": "The textContent property lets you read or change the text inside an element. Setting it replaces all the element's text.", "task": "Set the textContent of el to \"Hello!\"", "previewHTML": "

Old text

", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; }", "sandboxCSS": "", "initialCode": "", "solution": "el.textContent = \"Hello!\";", "codePrefix": "const el = document.querySelector(\"#msg\");\n", "codeSuffix": "", "previewContainer": "preview-area", "validations": [ { "type": "contains", "value": "textContent", "message": "Use the textContent property" }, { "type": "regex", "value": "el\\.textContent\\s*=\\s*[\"']Hello![\"']", "message": "Set el.textContent to \"Hello!\"" } ] }, { "id": "js-style", "title": "Change Style", "description": "Access an element's inline styles through the style property. CSS properties use camelCase in JavaScript, so background-color becomes backgroundColor.", "task": "Set el.style.backgroundColor to \"gold\"", "previewHTML": "
", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; }", "sandboxCSS": "", "initialCode": "", "solution": "el.style.backgroundColor = \"gold\";", "codePrefix": "const el = document.querySelector(\"#box\");\n", "codeSuffix": "", "previewContainer": "preview-area", "validations": [ { "type": "contains", "value": "style.backgroundColor", "message": "Use el.style.backgroundColor" }, { "type": "regex", "value": "\\.style\\.backgroundColor\\s*=\\s*[\"']gold[\"']", "message": "Set the background color to \"gold\"" } ] } ] }