Skip to content
Related Articles

Related Articles

HTML | DOM previousElementSibling Property

View Discussion
Improve Article
Save Article
  • Last Updated : 26 Jul, 2019

The previousElementSibling property in HTML DOM is used to return the previous element of the same level of the given element. If no previous element found on the same level then it returns null. It is a read-only property. It is similar to 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 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.


<!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() {
            var a = 
            document.getElementById("p").innerHTML = a.text;

Before click on the button:
After click on the button:

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!