codex-lv2-may-2025

Level Navigation: 1 2 3 4 5 6 7 Current Level: 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

Level 8: IDs and Testing

What You’ll Do

Add meaningful IDs to all elements and test that they can be accessed.

Instructions

💡 Code Hints

Need help with IDs? Check out these snippets:

✅ Check

  1. Open your webpage in a browser
  2. Open Chrome DevTools (F12) and go to the Console tab
  3. Type document.getElementById("your-input-id") and press Enter
  4. You should see the input element returned (not null)
  5. Test all your IDs this way to make sure they work
  6. Try using setProperty() to test element modification:
    • setProperty("your-input-id", "backgroundColor", "yellow")
    • setProperty("your-button-id", "border", "3px solid red")
  7. If any return null, check that the ID is spelled correctly in your HTML

🔍 Optional: Diving Deeper - DOM Operations

For extra practice, you can also test element access with:

console.log(document.getElementById("your-input-id"))

This will show you the full element object in the console, which can help you understand what properties and methods are available.

You can also use the native DOM style property to modify elements directly:

// Same as setProperty("your-input-id", "backgroundColor", "yellow")
document.getElementById("your-input-id").style.backgroundColor = "yellow";

// Same as setProperty("your-button-id", "border", "3px solid red")
document.getElementById("your-button-id").style.border = "3px solid red";

The DOM Operations approach is the standard way to manipulate styles in professional JavaScript development and is used across all major frameworks and libraries. Learning the native DOM API prepares you for real-world codebases where helper functions aren’t available.




Level Navigation: 1 2 3 4 5 6 7 Current Level: 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