# getElementByID (Shared)

> Finds the first element with an ID, starting at an element and going down through its children.

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

## Syntax

```lua
element|nil getElementByID(string id [, element startAt = root])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `id` | `string` | The ID to look for. |
| `startAt` | `element` | Where the search starts. It counts too. *(default: `root`)* |

## Returns

The element found, or `nil` if none has that ID.

## Example

```lua
local gate = getElementByID("lspd_gate", resourceRoot)
if gate then
    moveObject(gate, 3000, 1544.7, -1630.7, 10)
end
```

## See also

- [getElementID (Shared)](https://wiki.mymp.gg/en/getElementID.md): Reads an element's ID, the name getElementByID looks for.
- [setElementID (Shared)](https://wiki.mymp.gg/en/setElementID.md): Gives an element an id (a name), to find it later with getElementByID.
- [getElementsByType (Server)](https://wiki.mymp.gg/en/getElementsByType-server.md): Lists every element of a type below an element of the tree on the server.
