Complete the code to start a view transition when a button is clicked.
document.querySelector('button').addEventListener('click', () => { document.startViewTransition(() => { [1] }); });
The startViewTransition method expects a callback that changes the DOM content to trigger the transition. Updating document.body.textContent inside the callback starts the view transition.
Complete the code to check if the View Transitions API is supported in the browser.
if ([1] in document) { console.log('View Transitions API is supported'); } else { console.log('Not supported'); }
The method startViewTransition is the key function of the View Transitions API. Checking if it exists in document confirms support.
Fix the error in the code to properly use the View Transitions API to update a div's text.
const container = document.getElementById('container'); document.[1](() => { container.textContent = 'Updated content'; });
The correct method to start a view transition is startViewTransition on document. Other method names are invalid and cause errors.
Fill both blanks to create a view transition that changes the background color and text of a section.
const section = document.querySelector('section'); document.[1](() => { section.style.[2] = 'lightblue'; section.textContent = 'Background changed'; });
The method to start the transition is startViewTransition on document. To change the background color, use the CSS property backgroundColor.
Fill all three blanks to create a view transition that updates a list by adding a new item if the list has less than 5 items.
const list = document.querySelector('ul'); document.[1](() => { if (list.children.length [2] 5) { const newItem = document.createElement('[3]'); newItem.textContent = 'New item'; list.appendChild(newItem); } });
Use startViewTransition on document to start the transition. The condition checks if the list has less than 5 items using <. The new element to add is a list item li.
