capture and restore selections in HTML elements