Complete the code to apply a named action called 'focus' to the input element.
<input use:[1] />The named action 'focus' is applied using use:focus syntax in Svelte.
Complete the code to define a named action 'highlight' that changes the background color of an element.
function [1](node) { node.style.backgroundColor = 'yellow'; return { destroy() { node.style.backgroundColor = ''; } }; }
The function name must match the named action 'highlight' to be used as use:highlight.
Fix the error in the named action usage by completing the code to pass a parameter 'color' to the action.
<script> function highlight(node, [1]) { node.style.backgroundColor = color; return { update(newColor) { node.style.backgroundColor = newColor; }, destroy() { node.style.backgroundColor = ''; } }; } </script> <div use:highlight={'yellow'}>Highlight me</div>
The second parameter of the action function receives the parameter passed in the template, here named 'color'.
Fill both blanks to create a named action 'tooltip' that adds a title attribute and updates it when the parameter changes.
function [1](node, [2]) { node.title = text; return { update(newText) { node.title = newText; }, destroy() { node.title = ''; } }; }
The action is named 'tooltip' and the parameter holding the title text is 'text'.
Fill all three blanks to create a named action 'resize' that listens for window resize events and calls a callback parameter.
<script> function [1](node, [2]) { function onResize() { callback(); } window.addEventListener('resize', onResize); return { destroy() { window.removeEventListener('resize', [3]); } }; } </script>
The action is named 'resize', the parameter is 'callback', and the event listener is removed using the same function 'onResize'.