To get the previous sibling of an element with jQuery, you can use the .prev()
method. Here's an example code snippet that demonstrates how to get the previous sibling of an element with the class .timeslot-time
:
index.tsx337 chars7 lines
In the first example, we use the jQuery selector $('.timeslot-time')
to select the element with the class timeslot-time
. We then call the .prev()
method on this element to get its previous sibling.
In the second example, we use the document.querySelector()
method to select the element with the class timeslot-time
. We then access its previousElementSibling
property to get its previous sibling.
Note that the previousSibling
property in JavaScript can also return text nodes, whereas the previousElementSibling
property only returns element nodes.
gistlibby LogSnag