SALISBURY, Conn. (AP) _ Margaret Hamilton, the Wicked Witch of the West who melted at the feet of Dorothy in the 1939 film classic ''The Wizard of Oz,'' died Thursday of an apparent heart attack. She was 82.

The veteran of more than 75 films and scores of plays died at the Noble Horizons nursing home in Salisbury, where she had been in declining health for a year, said Joann Lunning, director of nursing.

She worked as a character actress for more than 50 years, including a five- year run as Cora, the kindly old storekeeper who appeared in commercials for Maxwell House coffee.

But she was best known for ''Oz.'' Generations of children thrilled at her depiction of the green-skinned witch, and with each showing of the film on television she received hundreds of letters from young fans.

The celebrity was ironic, for two reasons. She was a former kindergarten teacher and loved children. And she never thought the witch was her best work.

Her death leaves Ray Bolger, who played the Scarecrow, as the only surviving major cast member of the film. The others included Judy Garland as Dorothy, Jack Haley as the Tin Man, Bert Lahr as the Cowardly Lion and Billie Burke as Glinda the Good Witch.

In 1973, Miss Hamilton said she had turned down countless offers to recreate the role. ''I suppose I've turned down a fortune too, but I just don't want to spoil the magic. Little children's minds can't cope with seeing a mean witch alive again,'' she said.

''Many times, I see mothers and little children and the mothers always recognize me as the witch. Often, they say to the kids, 'Don't you know who she is? She's the witch in the 'Wizard of Oz 3/8' Then the kids look disappointed and say 'But I thought she melted.' It's as though they think maybe I'm going to go back and cause trouble for Dorothy again.''

A native of Cleveland, Miss Hamilton first got a taste of the theater in a class production in high school. But she was trained to teach kindergarten, and went on to operate private schools in Cleveland and Rye, N.Y.

But in 1927, she became a member of the Cleveland Play House, which now sponsors a scholarship fund in her name. Her first role was in a play entitled ''The Man Who Ate the Popomack''; in three years, she performed 25 roles.

From there, she won a part in ''Another Language,'' which played for a year on Broadway. She was hired to reprise her role in the film version in 1932, and that was the start of her Hollywood career.

She appeared in ''My Little Chickadee'' with W.C. Fields and Mae West, ''State of the Union,'' ''A Slight Case of Murder,'' ''Nothing Sacred'' and many others. As recently as 1971, she appeared in ''Brewster McCloud'' and ''The Anderson Tapes.''

The roles were not wide-ranging; her face, with the distinctive bump on her nose, led to parts as smarmy gossips, spinsters and maids.

''I've done some hard-bitten parts, but most of the time I've been the cantankerous cook or the acidulous aunt with a corset of steel and a heart of gold,'' she once said.

She continued a stage career, appearing in summer stock and local productions. In 1978-79, she returned to the Cleveland Play House to play a hypochondriac in Emlyn Williams' ''Night Must Fall.''

She also was a familiar voice on radio, and appeared in numerous productions in the early days of live television. In addition to her roles in commercials, she did turns in soap operas and guest spots on such situation comedies as ''The Addams Family'' and ''The Patty Duke Show.''

Miss Hamilton worked as a volunteer for various causes - disabled veterans, a theater school in New York, the Friends for Animals.

''Even when I played the Wicked Witch ... I had a soft spot in my heart for the Cowardly Lion because the lion is part of our wildlife,'' she recalled in a 1980 article she wrote for The New York Times, urging that safeguards be established to protect porpoises.

Michael Thomas, her agent, said she was survived by a son, Hamilton Meserve, of Millbrook, N.Y. She had divorced her husband, landscape architect Paul Meserve, in 1938.

Thomas said funeral services would be private, and a memorial would be held at a later date.