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

clitetailor picture clitetailor  路  3Comments

st-schneider picture st-schneider  路  3Comments

noypiscripter picture noypiscripter  路  3Comments

Rich-Harris picture Rich-Harris  路  3Comments

juniorsd picture juniorsd  路  3Comments