jquery get .timeslot-time one simling up in javascript

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.tsx
// using jQuery to get the previous sibling of an element with class 'timeslot-time'
var prevSibling = $('.timeslot-time').prev();

// using JavaScript to get the previous sibling of an element with class 'timeslot-time'
var timeslotTime = document.querySelector('.timeslot-time');
var prevSibling = timeslotTime.previousElementSibling;
337 chars
7 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