(Reuters) - Target Corp beat expectations for earnings and raised its full-year outlook on Wednesday as its investments in same-day delivery and pick-up services increased traffic to its website and stores, sending shares 19% higher.

The retailer has spent billions of dollars on its push to compete with the ease of delivery provided by Amazon.com Inc and Walmart Inc, buying grocery delivery firm Shipt, and building in-store pickup and drive-up services.

Target said one out of five customers who used its same-day service in the quarter were new, with shoppers collecting their orders from stores within a couple of minutes of placing them through the company’s mobile app or website.

“Q2 could not have gone better for Target,” Charlie O’Shea, a vice president at ratings agency Moody’s, said of the results.

Led since 2014 by retail-industry veteran Brian Cornell, Target has bounced back from a slide three years ago which saw its margins drop, prompting a rethink that has seen it remodel hundreds of stores each year since.

Like Walmart it has refitted its business to deal with the challenge presented by Amazon and other online retailers, also developing its line of own-brand goods to boost profits.

Wednesday’s results showed the company’s same-day services drove more than three-fourths of a 34% increase in comparable digital sales in the quarter. Those online sales accounted for more than half of its total same-store sales.

FILE PHOTO: An empty shopping cart stands outside a target store during a Black Friday sales event in Westbury, New York, U.S., November 23, 2018. REUTERS/Shannon Stapleton

“Because these options leverage our store infrastructure, technology and teams, same-day fulfillment delivers outstanding financial performance as well,” Cornell told a post earnings call.

The company’s stock, which had already risen 29% this year, jumped 19% to a record high of $102.02, driving gains in other retail players and adding to broad gains for Wall Street.

NO MARGIN SLIP

The quicker deliveries, Target executives said, also powered profitability as margins expanded for the first time in nearly three years, rising 30 basis points to 30.6% in the quarter.

That reflected a stronger product mix and optimization of pricing, the company said, at a time when Walmart’s margins dropped 46 basis points. Macy’s, Kohl’s and J.C. Penney have all reported disappointing results in the past week.

“While many department store peers struggle to sustain positive traffic and stable gross margins, Target is finding the right balance,” Evercore analyst Greg Melich said.

Target’s comparable sales rose by a better-than-expected 3.4% as demand for apparel, toys and beauty products rose. Late in the quarter, the retailer also benefited from back-to-school promotions.

Its strategy of opening smaller locations in college towns and urban areas, and stocking more own-brand goods, helped store traffic grow 2.4%.

Earlier this week, the company said it was starting a new food and beverage brand, Good & Gather, that would hit stores in September.

Target expects full-year adjusted profit to be between $5.90 and $6.20 per share, up from the prior range of $5.75 to $6.05 per share. The outlook accounted for potential additional U.S. tariffs on Chinese imports.

Excluding certain items, it earned $1.82 per share, beating the average analyst estimate by 20 cents. Total revenue rose 3.6% to $18.42 billion, above expectations of $18.34 billion.