Skip to content

How to get a reference to the underlying DOM element #915

Answered by ramilamparo
denisborovikov asked this question in Q&A
Discussion options

You must be logged in to vote

Seems that there are no props provided for binding elements.

One workaround is:

<script>
let container
$: input = container.querySelector("input")
</script>

<div class="content" bind:this={container}>
    <Input />
</div>

The input variable will contain the underlying input element. The content class is used so it wouldn't affect the layout.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@danielo515
Comment options

Answer selected by denisborovikov
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants