Extended example to use onHide event