StepsEasy
JS Selecting Elements - Example
Run
Reset
Destroy & Close
← Back to lesson
Code Editor
javascript
// Selecting elements const title = document.getElementById('title'); const items = document.querySelectorAll('.item'); const first = document.querySelector('.item'); // Changing content title.textContent = 'New Title'; title.innerHTML = '<em>New Title</em>'; // Changing styles title.style.color = 'blue'; title.style.fontSize = '24px'; // Adding/removing classes title.classList.add('active'); title.classList.remove('hidden'); title.classList.toggle('highlight');
Result
Click "Run" to execute the code...
Loading runtime...
Ready
JAVASCRIPT | In-Browser Execution