useParentElement
Get parent element of the given element
Demo
Parent element tag: DIV
Usage
When no argument is passed, it will return the parent element of the current component.
js
import { useParentElement } from '@vueuse/core'
const parentEl = useParentElement()
onMounted(() => {
console.log(parentEl.value)
})It can also accept a ref as the first argument.
ts
import { useParentElement } from '@vueuse/core'
// Don't forget to bind the ref to the element
const tooltip = ref<HTMLElement | undefined>()
const tooltipWrapper = useParentElement(tooltip)
onMounted(() => {
console.log(tooltipWrapper.value)
})js
import { useParentElement } from '@vueuse/core'
// Don't forget to bind the ref to the element
const tooltip = ref()
const tooltipWrapper = useParentElement(tooltip)
onMounted(() => {
console.log(tooltipWrapper.value)
})Type Declarations
typescript
export declare function useParentElement(
element?: MaybeRefOrGetter<HTMLElement | SVGElement | null | undefined>,
): Readonly<Ref<HTMLElement | SVGElement | null | undefined>>Source
Contributors
Changelog
v10.0.0-beta.4 on 4/13/20234d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter0a72b - feat(toValue): rename resolveUnref to toValuev10.0.0-beta.2 on 3/28/2023