The baby girl was discovered by pets that had picked up on her scent coming from the bag. Keith Garvin of NBC station KPRC reports.

Child welfare officials have taken custody of a newborn girl who was found abandoned in a plastic grocery bag by passing dogs in Cypress, Texas.

The infant was in good condition at Texas Children's Hospital but was lucky to be alive, doctors and law enforcement officials said.

"If it had not have been for the resident that came out to walk her dogs, that child may have laid there all night (and) possibly would have died," said Harris County sheriff's Sgt. Gordon Trott told NBC station KPRC of Houston.

The girl was found by a fence about 7 p.m. (8 p.m. ET) Tuesday near an apartment complex in Cypress, a city of 57,000 about 25 miles northwest of Houston. Overnight low temperatures there have dropped into the low 40s in recent days.

About 3 inches of her umbilical cord was still attached, and while it had been cut, it hadn't been clamped, Trott said. That made her situation especially perilous.

"If the cord is not clamped before it's cut, there is a risk of the baby bleeding out through the unclamped cord, which could have led to a baby's death," Tiffany McKee-Garrett, a pediatrician at Texas Children's Hospital, told KPRC.

Sheriff's deputies were still searching Thursday for the baby's mother, who they said could face a felony child endangerment charge.

Child welfare officials said they were perplexed by the case, because Texas law allows anyone to drop off a newborn at a hospital or a fire station — no questions asked.

"All you have to do is hand the baby over," said Gwen Carter, a spokeswoman for Harris County Child Protective Services.

Follow M. Alex Johnson on Twitter and Facebook.

Watch US News crime videos on NBCNews.com