My goal is to determine if an element is the last one in the container div by checking the length of the next element with the class .item
. If this next element exists, it means that I am not currently at the end of the container div.
if($(this).next('.item').length < 1) {
console.log('element is last');
}
If the element is indeed the last one, I want to reposition it by inserting it before the previous .item
, making it the second-to-last element instead.
I have explored using .insertBefore()
, but I am unsure about which specific "before" element to target.