Skip to content

useParentElement

Category
Export Size
467 B
Last Changed
4 days ago

Get parent element of the given element

Demo

Current element tag: Finding...

Parent element tag: Finding...

Usage

When no argument is passed, it will return the parent element of the current component.

vue
<script setup lang="ts">
import { 
useParentElement
} from '@vueuse/core'
const
parentEl
=
useParentElement
()
onMounted
(() => {
console
.
log
(
parentEl
.
value
)
}) </script>

It can also accept a ref as the first argument.

vue
<script setup lang="ts">
import { 
useParentElement
} from '@vueuse/core'
import {
shallowRef
} from 'vue'
const
tooltip
=
shallowRef
<HTMLElement | undefined>()
const
tooltipWrapper
=
useParentElement
(
tooltip
)
onMounted
(() => {
console
.
log
(
tooltipWrapper
.
value
)
}) </script> <template> <
div
>
<
p
ref
="
tooltip
" />
</
div
>
</template>

Type Declarations

ts
export declare function 
useParentElement
(
element
?:
MaybeRefOrGetter
<HTMLElement | SVGElement | null | undefined>,
):
Readonly
<
ShallowRef
<HTMLElement | SVGElement | null | undefined>>

Source

SourceDemoDocs

Contributors

NoiseFan

Changelog

No recent changes

Released under the MIT License.