A change event is a native DOM event: the browser dispatches it when a form control’s value changes. A handler can use the event to find the selected value and update another element. section 14.2 section 7.3
Choose a layout
A select menu calls updateLayout(event) on change. The handler reads event.target.value and passes it to setAttribute('layout', ...). The custom element then responds through attributeChangedCallback, replacing its displayed template with the chosen layout. section 7.3
Listing 7.8. Setting the layout attribute from a menu outside of our component
<body>
<p>
<select onchange="updateLayout(event)"> #1
<option value="none">none</option>
<option value="default-card">default</option>
<option value="variation">variation</option>
</select>
</p>
<biz-card layout="none"></biz-card>
<script>
function updateLayout(event) {
document.querySelector('biz-card').setAttribute('layout',
event.target.value); #2
}
</script>
</body>
See the menu and handler together: the event supplies the selected value, while setAttribute passes it to the custom element. section 7.3
Need a component to announce a change of its own? That is a separate choice: JavaScript can create and dispatch a CustomEvent for other code to hear. The select menu’s change event is instead generated by the browser. section 14.2

















