0Pricing
Sveltejs Academy · Lesson

bind:this for DOM Element References

Obtain a reference to a DOM node for imperative interactions.

Getting a DOM Reference

Use bind:this to obtain a reference to a DOM element, similar to useRef in React.

Declare and Bind

Declare a variable, then bind it.

<script>
  let inputEl;
</script>

<input bind:this={inputEl} />

All lessons in this course

  1. bind:value for Text Inputs
  2. bind:checked for Checkboxes
  3. bind:group for Radio and Checkbox Groups
  4. bind:this for DOM Element References
← Back to Sveltejs Academy