onResize() utility function that adds detection of size changes to any DOM element