JavaScript node.previousSibling Property

You are Here:

JavaScript node.previousSibling Property

The node.previousSibling property returns the previous node of the specified node, in the same tree level.

Note: This property is read-only.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <div>Div 1</div> <h1>Heading 1</h1> <p>Paragraph 1</p> <p>Click the button to find the previousSibling of h1 tag.</p> <button onclick="myFunction()">Click Me</button> <p id="point"></p> <script> var x = document.getElementById("point"); var y = document.getElementsByTagName("h1")[0]; function myFunction(){ //Try to replace "previousSibling" by "previousSibling.previousSibling" x.innerHTML = y.previousSibling.nodeName; } </script> </body> </html>

Syntax

node.previousSibling

Return Values

ValueExplanation
ObjectReturns the previous node of the specified node, in the same tree level.
nullIf there in no previous sibling.

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author