Svelte: How do I get an element reference from within component?

Created on 31 Jul 2019  路  2Comments  路  Source: sveltejs/svelte

How do I access an element reference from within my component?

// thingo.svelte
<div />

<script>
  console.log(this.querySelector('div')) // ???
</script>

Most helpful comment

Hi,

You can use the bind:this={myElement} attribute on your DOM element, as stated here in the API documentation of Svelte.

Hope it helps.

All 2 comments

Hi,

You can use the bind:this={myElement} attribute on your DOM element, as stated here in the API documentation of Svelte.

Hope it helps.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mmjmanders picture mmjmanders  路  3Comments

AntoninBeaufort picture AntoninBeaufort  路  3Comments

davidcallanan picture davidcallanan  路  3Comments

juniorsd picture juniorsd  路  3Comments

thoughtspile picture thoughtspile  路  3Comments