Toggle Active Class
JavaScript
Easy
3 views
Problem Description
You have a button with id btn and a box with id box. When user clicks button, toggle class active on #box. Write the JavaScript code.
Output Format
No output (DOM change).
Constraints
Assume HTML has #btn and #box elements.
Official Solution
const btn=document.getElementById('btn');const box=document.getElementById('box');btn.addEventListener('click',()=>{box.classList.toggle('active');});
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!