Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
Every button, image, paragraph, and div is a treasure! But before you can change them, you need to find them first. That's where element selection comes in!
Tell JavaScript which element you want by using a selector (ID, class, or tag name)
document.querySelector('.button')Save the element in a variable so you can use it multiple times
const btn = elementNow do whatever you want - change text, colors, add clicks, anything!
btn.textContent = 'Hi!'Each way is perfect for different situations. Click each card to see it in action!
Best for: Unique elements like header, main button, or logo
document.getElementById('submit')Best for: Multiple elements that share styling (all buttons, all cards)
document.querySelector('.card')Best for: Selecting all of one type (all paragraphs, all images)
document.querySelector('button')querySelector('button')querySelector('.button')const btn = querySelector('.btn');
btn.click(); // Error if not found!const btn = querySelector('.btn');
if (btn) btn.click();// Script at top of page
const btn = querySelector('.btn'); // null!// Wait for page to load
document.addEventListener('DOMContentLoaded', () => {\n const btn = querySelector('.btn');\n});