.previousElementSibling

Element? ParentNode.previousElementSibling

A property containing the previous element sibling of a node - it does not count text nodes. Returns null if no such element exists. This property is read-only - it cannot be set.

let previousEl = node.previousElementSibling;

See also: .nextElementSibling

Example

HTML:

<p>
    All
    <strong>large</strong>
    goats
    <em>are</em>
    delicious!
</p>

JavaScript:

let prev = document.query("em").nextElementSibling;

Result is the <strong>large</strong> element.