Open In App
Related Articles

HTML DOM previousElementSibling Property

Improve Article
Save Article
Like Article

The previousElementSibling property in HTML DOM is used to return the previous element of the same level as the given element. If no previous element is found on the same level then it returns null. It is a read-only property. It is similar to the previousSibling property but the difference is previousSibling property returns the previous sibling node as an element node, a text node, or a comment node, while the previousElementSibling property returns the previous sibling as an element node. 



Return value: This property returns a previous sibling of the specified element or null if the current element has no previous sibling. 

Example: In this example, we will use the previousElementSibling property.


<!DOCTYPE html>
        HTML DOM previousElementSibling Property
        DOM previousElementSibling Property
    <h4 id="h42">Web Languages:</h4>
    <select size="4">
        <option id="Select">XML</option>
    <button onclick="Geeks()">
        Previous Element Sibling
    <p id="p"></p>
        function Geeks() {
            let a = document.getElementById("Select")
                          = a.text;



Note: Don’t use white space between two sibling elements, otherwise, the result will be “undefined”. 

Supported Browsers: The browser supported by DOM previousElementSibling property are listed below:

  • Google Chrome 2.0
  • Internet Explorer 9.0
  • Firefox 3.5
  • Opera 10.0
  • Safari 4.0

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 15 Jun, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials