{ "$schema": "../schemas/code-crispies-module-schema.json", "id": "js-dom", "title": "JS DOM", "description": "Learn to select and modify HTML elements using JavaScript DOM methods like querySelector and textContent.", "mode": "javascript", "difficulty": "beginner", "lessons": [ { "id": "js-query", "title": "querySelector", "description": "Use document.querySelector() to find the first element matching a CSS selector. It returns a single element you can then modify.", "task": "Select the h1 element and store it in a constant called title", "previewHTML": "
Waiting...
", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; }", "sandboxCSS": "", "initialCode": "", "codePrefix": "", "codeSuffix": "\ndocument.getElementById('out').textContent = title.tagName;", "solution": "const title = document.querySelector('h1');", "previewContainer": "preview-area", "validations": [ { "type": "contains", "value": "querySelector", "message": "Use document.querySelector() to select an element" }, { "type": "regex", "value": "querySelector\\(['\"`]h1['\"`]\\)", "message": "Pass 'h1' as the selector" }, { "type": "regex", "value": "const\\s+title\\s*=", "message": "Store the result in a constant called title" } ] }, { "id": "js-text", "title": "textContent", "description": "The textContent property lets you read or change the text inside an element. Setting it replaces all existing text.", "task": "Select the .msg element and set its textContent to \"Done!\"", "previewHTML": "Waiting...
", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; }", "sandboxCSS": "", "initialCode": "", "codePrefix": "", "codeSuffix": "", "solution": "document.querySelector('.msg').textContent = \"Done!\";", "previewContainer": "preview-area", "validations": [ { "type": "contains", "value": "querySelector", "message": "Use querySelector to find the element" }, { "type": "contains", "value": "textContent", "message": "Use the textContent property to change the text" }, { "type": "regex", "value": "(\"Done!\"|'Done!'|`Done!`)", "message": "Set the text to \"Done!\"" } ] }, { "id": "js-style", "title": "Inline Styles", "description": "Access the style property to set inline CSS on an element. CSS properties with dashes become camelCase: background-color becomes backgroundColor.", "task": "Select the .box element and set its style.color to \"coral\"", "previewHTML": "Style me!
", "previewBaseCSS": "body { font-family: system-ui, sans-serif; padding: 1rem; } .box { font-size: 1.5rem; font-weight: bold; }", "sandboxCSS": "", "initialCode": "", "codePrefix": "", "codeSuffix": "", "solution": "document.querySelector('.box').style.color = \"coral\";", "previewContainer": "preview-area", "validations": [ { "type": "contains", "value": "querySelector", "message": "Use querySelector to find the element" }, { "type": "contains", "value": ".style.", "message": "Use the .style property to set CSS" }, { "type": "regex", "value": "style\\.color\\s*=", "message": "Set style.color on the element" }, { "type": "regex", "value": "(\"coral\"|'coral'|`coral`)", "message": "Set the color to \"coral\"" } ] }, { "id": "js-classlist", "title": "classList", "description": "The classList property provides methods to add, remove, or toggle CSS classes on an element without touching other classes.", "task": "Select the .card element and add the class \"active\" using classList.add()", "previewHTML": "