useParentElement ​
Get parent element of the given element
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 ​
Anthony Fu
JD Solanki
Changelog ​
v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
0a72b
- feat(toValue): rename resolveUnref
to toValue
v10.0.0-beta.2
on 3/28/2023