How to detect whether an element is in a scrollable parent

Just think of having an element in a scrollable parent (the CSS property overflow is set to scroll) and you want to test whether the element is visible or not.

Using this little function you can do the trick:

And here’s a small use case – this one scrolls the element into the visible region, if it is not already in the view: