# getAttachedElements (Shared)

> Lists the elements attached directly to an element.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Attachments
- **URL**: https://wiki.mymp.gg/en/getAttachedElements

## Syntax

```lua
table getAttachedElements(element element)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `element` | `element` | The target element. |

## Returns

A table with the elements attached to it. It is empty when nothing is attached.

Only the elements hanging directly on it are listed, not the ones hanging on those.

## Example

```lua
addEventHandler("onElementDestroy", root, function()
    if getElementType(source) ~= "vehicle" then
        return
    end
    for _, attached in ipairs(getAttachedElements(source)) do
        if getElementType(attached) == "object" then
            destroyElement(attached)
        end
    end
end)
```

## See also

- [attachElements (Shared)](https://wiki.mymp.gg/en/attachElements.md): Hangs one element on another. From then on it follows the target until it is detached.
- [getElementAttachedTo (Shared)](https://wiki.mymp.gg/en/getElementAttachedTo.md): Tells which element an element is attached to.
- [detachElements (Shared)](https://wiki.mymp.gg/en/detachElements.md): Detaches an element from the element it hangs on. It stays where it is.
