Javatpoint Logo
Javatpoint Logo

previousElementSibling Property in javascript

The javascript previousElementSibling Property works to display the previous node of the required or input node as a Node object. If the given node is the initial element of the list, then the nodes object displays null.

The previousElementSibling Property is used to get the element that came before specified in the same tree level. This Property is used for reading only on the web page.

Syntax

The following syntax gives an earlier sibling node of the list using previousElementSibling Property.

Return value

  • The Property displays a previous sibling node as an element.
  • If the previous sibling node is unavailable, then the Property gets a null.

Supported Browsers

The following list of the browsers that the previousElementSibling Property works with:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari
  • Edge

Examples

The following example displays the multiple values or nodes using the previousElementSibling Property.

Example 1

The basic previousElementSibling Property in the javascript example displays below. Here we can get the previous sibling node of the second node.

Output

The image gets the earlier node of the required node using javascript Property.

Example 2

The basic previousElementSibling Property displays output in the console log function. Here we can get the previous sibling node of the third node.

Output

The image gets the null value because of the first required node using the javascript Property.

previousElementSibling Property in javascript

Example 3

The basic previousElementSibling Property in javascript with condition example displays below. Here we can get the previous sibling nodes of the first, third, and last node simultaneously. We can use white space or a separate tag for the list item.

Output

The image gets the multiple earlier node of the required node using javascript Property.

previousElementSibling Property in javascript

Example4

The previous sibling node property is used for all tags without whitespace. It displays data as a list but does not necessarily list tags.

Output

The image gets the multiple earlier node of the required node with a list tag.

previousElementSibling Property in javascript

Conclusion

The javascript previousElementSibling element displays the previous value of the list without whitespace. The list data, hash data, and other multiple information operate, control, and display using previousElementSibling Property.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA