On this page
useParentElement
Category | Elements |
---|---|
Export Size | 496 B |
Last Changed | 2 weeks ago |
Get parent element of the given element
Usage
When no argument is passed, it will return the parent element of the current component.
import { useParentElement } from '@vueuse/core'
const parentEl = useParentElement()
onMounted(() => {
console.log(parentEl.value)
})
It can also accept a ref
as the first argument.
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)
})
Type Declarations
export declare function useParentElement(
element?: MaybeRefOrGetter<HTMLElement | SVGElement | null | undefined>
): Readonly<Ref<HTMLElement | SVGElement | null | undefined>>
Source
© 2019-present Anthony Fu
Licensed under the MIT License.
https://vueuse.org/core/useParentElement/