Skip to content

useParentElement

Category
Export Size
496 B
Last Changed
last year

Get parent element of the given element

Demo

Parent element tag: Finding...

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

SourceDemoDocs

Contributors

Anthony Fu
青椒肉丝
JD Solanki

Changelog

v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
0a72b - feat(toValue): rename resolveUnref to toValue
v10.0.0-beta.2 on 3/28/2023
e8168 - feat: new function (#2855)

Released under the MIT License.