Build a component that shows and hides a content panel with conditional rendering.

The component must render a <button> element with the class toggle labeled Toggle, and a <div> element with the class panel whose text is exactly Panel content. The panel must be hidden initially — not just visually hidden, but completely absent from the DOM (use the lwc:if directive). Clicking the toggle button shows the panel; clicking it again hides the panel.

The starter template renders the panel unconditionally — your job is to make it conditional and wire up the toggle behavior.

Examples:

Initial render: <button class="toggle">Toggle</button> (no .panel element in the DOM) Click Toggle -> <div class="panel">Panel content</div> appears Click Toggle again -> the .panel element is removed from the DOM
LWC

Preview

Press Run & Test to compile and preview your component.

Test results

Tests run automatically after each compile.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In