Optimized JS by eliminating repeated jQuery selector calls to div.popup, and chaining operations.