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 |
JavaScript confirm method invokes a function that asks the user for a confirmation dialogue on a particular action. The confirm () method uses a window object to invoke a dialogue with a question and two option buttons, OK and Cancel. If the user selects the...
3 min read
What is Lodash? Lodash is a JavaScript library that has a lot of inbuilt functions, and it provides utility and more functionality to the developers. It is built upon the underscore.js library of JavaScript. Lodash._chain() Method This method is used to wrap the value which we get from...
3 min read
? If you are a Smartphone user, it is quite possible that your Smartphone may work on Android OS. However, if your phone's browser is configured to disable JavaScript, you will certainly experience an unsatisfactory web browsing. So, it is necessary to use the web browser...
2 min read
In JavaScript, the italics() method is used to display an italic string. It makes the text similar to the text is in <i> </i> (italic tag). Because the italics() method is a method of string object, so it must be invoked through a specific instance...
2 min read
JS First Class Function JavaScript is a dynamic scripting language that allows us to use it in the form of an object-oriented style or functional style. In the same way, one such feature of JavaScript is the First class function. In this section, we will discuss the...
4 min read
The javascript sessionStorage object is a property of the window object that all modern browsers have. The protocol, hostname, and port of the page are linked to any information in sessionStorage. Each window has its session storage. The javascript sessionStorage is a procedure that aids...
6 min read
A 2D drawing context's translate() method is used. The canvas and its origin are moved by x and y units using the translate(x,y) method. Otherhand, The drawing position (0,0) on the canvas is remapped by the translate() method. The value is included in the x- and...
6 min read
Javascript getModifierState() KeyboardEvent uses to know which keypresses are on the keyboard. The event returns true if modifiers keys are pressed or clicked off the keyboard. We can use the pressed, clicked key, and the keyboard event activates the function. Syntax The syntax uses the javascript tag...
3 min read
The unique feature of async generator functions in javascript is their support to both await and yield. It returns an async iterator rather than a promise or iterator. The async generator functions are distinct from async functions and the generator functions in javascript. The () function...
3 min read
The human eye takes a long time to parse large numerical literals, particularly if many repeated digits exist. A new JavaScript programming feature allows underscores to be used as separators in numerical literals, which makes them easier to understand. A JavaScript feature called numeric separators enables us...
3 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