DOM Manipulation
Beginner
15 XP
You're trying this as a guest: your result shows here but isn't saved.
Sign in
Learn the fundamentals of manipulating the DOM with JavaScript.
Tasks:
- Create a function
createCard(title, body) that returns a div element with class 'card', containing an h2 with the title and a p with the body.
- Create a function
toggleVisibility(elementId) that toggles the 'hidden' class on the element with the given ID.
- Create a function
updateCounter(buttonId, displayId) that increments a counter each time the button is clicked and updates the display element.
Print the results of each function to verify they work.
To pass
- Card element should have class 'card'
- Card h2 should contain the title
- createCard should return a div element
Need a hint?
- Use document.createElement('div') to create elements.
- Set element.className = 'card' or use classList.add('card').
- Use element.textContent = 'text' to set text, appendChild() to nest elements.