If the text inside the .newsDate matches the previous or next .newsDate, I want to make its position sticky when scrolling, until it reaches the next .newsMiddleCont div.
What I'm trying to achieve:
The same date on multiple news items should stick if they were published on the same day.
The current code is not behaving as intended.
It applies and removes the sticky position to all .newsDate elements instead of only when .newsMiddleCont is visible and when the classes have matching innerText.
EDIT:
Further information:
The sticky behavior should be based on the date in .newsDate.
In my example HTML, the first "28. September 2022." should remain sticky until it reaches the second "28. September 2022."; and then continue until "13. October 1999.", after which it becomes static. This process repeats for similar scenarios.
IMPORTANT:
Dates should scroll uniquely. As we scroll down, the date sticks and moves accordingly. If the next article has the same date, the date shifts to that post. If the dates differ, the date stays at the bottom of the corresponding post and scrolls along with it.