PreviousSibling Property in Javascript18 Mar 2025 | 5 min read The previousSibling property serves to get the previous or earlier node of the given node as a Node object. If the given node is the first item in the list, then the node object shows null. The previousSibling property displays the element that came before the one you specified on the same level of the tree. The property is used to display previousSibling node, and it needs to return the preceding sibling node as a text node, element node, or comment node. This property can be read only for the web page. Note that the children's property works to get back all of an element's children. We can get the previous sibling node in the alert, console, and innerHTML function. Syntax The following syntax gives the previous sibling node of the list. Return value
Note Don't put whitespace between two elements already close to each other, or the result will be "undefined."ExamplesThe following example shows the output of the multiple values or nodes using previousSibling property. Example 1 The basic previousSibling property in the javascript example shows below. Here we can get the previous sibling node of the second node. Output The image displays the previous sibling node's value as an output. ![]() Example 2 The basic previousSibling property shows output in the console log function. Here we can get the previous sibling node of the third node. Output The image shows the previous sibling node's value as an output. ![]() Example 3 The basic previousSibling property in javascript with condition example shows below. Here we can get the previous sibling node's available value. The property displays the list value if the previous sibling node is available. The property shows a null value if the previous sibling nodes are unavailable. Output The image displays the previous sibling node's value as an output. The output is null because the previous sibling node is unavailable. ![]() Example 4 The basic previousSibling property in javascript with condition example shows below. Here we can get the previous sibling node's available value if the list gives without space. The list tag place space then the data shows undefined. Output The image displays an undefined value (space in the list ) as an output. ![]() Example 5 The basic previousSibling property in javascript with condition example shows below. Here we can get the previous sibling nodes of the first, third and last node simultaneously. Output The image displays the previous sibling node's value as an output. The output is null because the previous sibling node is unavailable. ![]() Example 6 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 displays the previous sibling nodes of the second nodes. ![]() Supported BrowsersHere is a list of the browsers that the previousSibling property works with:
ConclusionThe previousSibling node finds the earlier or before node of the required node without whitespace in the list tag. It is a basic and required JavaScript function for the list type of data or array type of information. Next TopicJavaScript sessionStorage |
The focusout event of JavaScript is the event handler that executes when the element is just about to lose focus. Other than this, we have also learned about blur, which is also an event handler used in JavaScript. Both blur and focusout are the focus...
3 min read
? Yes, it is a case sensitive language, which means the identifiers, keywords, variables, and function names must be written with a consistent capitalization of letters. Like many other programming languages, JavaScript has a set of rules for writing JavaScript programs or codes. Using the correct capitalization...
2 min read
The mousedown event uses the mouse movement on the web page using the javascript functionality. The mouse-down event works on the laptop's mouse, or single mouse click. If we press the on a laptop, the mouse down event starts its handling functionality. Syntax The following syntax shows...
3 min read
? As we all know, the variable declaration is one of the basic and essential aspects of any programming language such as C language, C++, etc. However, JavaScript has a small odd, known as Hoisting, which can turn a flawless-looking declaration into a subtle bug. Hoisting In JavaScript,...
3 min read
We often come across charts on analytics-based sites or some websites that contain surveys on some common agendas like population, percentage, and whatnot. These charts are often used in the Data Interpretation field to create network shares or profit distribution in core sectors. However, if we...
11 min read
Concept Design patterns can be termed as well-documented solutions to the most commonly occurring problems in software engineering. It turns quite hectic for developers to bang out their heads on the problem that someone else has already solved. Every developer aspires to write industrial-level code that...
9 min read
The mouse rolls up or down the web page and starts to operate the mouse wheel function using the "onwheel" javascript. We can use the "onmousewheel" event, but it deprecates in the javascript. We can use the javascript for the "onwheel" attribute instead of the "onmousewheel" event. Syntax The...
3 min read
We will understand how to manage <select> option in JavaScript in this tutorial. HTML Select Option A <select> option facilitate us the options list. It permits us to choose a single or more than one option. We use the <option> and <select> elements for forming a <select>...
4 min read
The ability to track DOM tree modifications is provided via the MutationObserver interface. It is intended to take the place of the ious Mutation Events functionality, which was included in the DOM3 Events definition. The DOM can often change in complex web projects. Because of this,...
7 min read
The javascript removes the single and multiple classes using a simple method. We can use the query selector with the remove() method. The remove method requires the classList keyword to get the multiple classes. The multiple classes use the "for" loop in the javascript. Syntaxes The syntax...
5 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India