Web APIs

Element.previousElementSibling

Try the free JavaScript compiler

Find the preceding element sibling, skipping non-element siblings. Example console output: true.

Formal Syntax & Structure

javascript syntaxjavascript
element.previousElementSibling

Return Value

Element or null

Previous element sibling or null.

Working Example

Example Snippetjavascript
const root=document.createElement("div"); const a=document.createElement("i"),b=document.createElement("b"); root.append(a,"gap",b); console.log(b.previousElementSibling===a);
JavaScript Reference