SAN BERNARDINO, Calif. -- An apparent murder-suicide inside an elementary school classroom in San Bernardino left a teacher, a student and the shooter dead and another student critically wounded, police said.

Police do not believe the children were targeted but were close to the female teacher at North Park School when the suspect came to the classroom to visit and then opened fire with a handgun, police Capt. Ron Maass said at a news conference.

“There was no indication the gun was visible upon his arrival at the school,” Maass said.

A police officer stands guard outside the North Park School after a shooting, Monday, April 10, 2017, in San Bernardino, California. AP

The students were taken to a hospital after what was believed to be a domestic dispute, San Bernardino City Unified School District spokeswoman Maria Garcia told news station KNBC-TV.

Get Breaking News Delivered to Your Inbox

San Bernardino Police Chief Jarrod Burguan said 8-year-old Jonathan Martinez died after he was airlifted to the hospital. The other student, a 9-year-old, was in stable condition at the same hospital. The chief did not release the other student’s name.

School staff greet students at North Park Elementary School, in relief at Cajon High School, Mon., April 10, 2017, in San Bernardino, Calif., after a deadly shooting occurred at the elementary school. AP

On the police department’s Twitter feed, the gunman was identified as Cedric Anderson, 53, of Riverside.

The slain teacher was identified as Karen Smith, 53, who police said was Anderson’s estranged wife. She was a teacher in the special-needs classroom for students in first through fourth grades.

Suspect in shooting identified as Cedric Anderson, age 53, resident of Riverside, CA. pic.twitter.com/H9YYQZvZud — San Bernardino PD (@SanBernardinoPD) April 10, 2017

Victim in school shooting identified as Karen Smith, age 53, estranged wife of suspect. pic.twitter.com/IaC7RCtVhl — San Bernardino PD (@SanBernardinoPD) April 10, 2017

Anderson had posted on social media last month that his wife was “an angel.”

On what appeared to be his Facebook page, Anderson also posted photos in March with Karen Elaine Smith. Police say the couple had been estranged for at least a month.

Anderson posted a video in February saying she’s “making me really happy.” In the 12-second clip, he also said, “She knows when to ignore me” as he laughed and flashed a smile.

He said, “that makes a happy marriage.”

A post on what appeared to be Karen Smith’s Facebook page invited friends to the couple’s wedding in January. Anderson posted several photos of the wedding and their honeymoon in Sedona.

Garcia said all other students were safe.

Police were searching Anderson’s home, CBS Los Angeles reported.

Burguan tweeted earlier on Monday, “We believe this to be a murder suicide.”

We believe this to be a murder suicide. Happened in a class room. Two students have been transported to the hospital. — Chief Jarrod Burguan (@SBPDChief) April 10, 2017

The school, which has about 600 students in kindergarten through sixth grades, was placed on lockdown. Students were being taken to a local college campus, Garcia said. Students gathered on a field and a blacktop basketball court inside the fenced-in grounds of the campus near a line of school buses.

Police cars escort students in a bus after a shooting at North Park Elementary School, to be reunited with their parents in San Bernadino, Calif., on Mon., April 10, 2017. Reuters

Police told parents to go to a nearby high school to pick up their kids.

“Parents bring ID to be reunited with children at Cajon High School,” the San Bernardino Police Department tweeted. “Please be patient as it may be about 3 hours before students released.”

Parents bring ID to be reunited with children at Cajon High School. Please be patient as it may be about 3 hours before students released. — San Bernardino PD (@SanBernardinoPD) April 10, 2017

A robocall was sent out to alert parents about the incident, CBS Los Angeles reported. Others learned about the shooting through word-of-mouth and local media.

Frantic parents ran up a sidewalk looking for information about their children. Several parents interviewed on TV said their children were too young to carry mobile phones, so they had not been able to contact them to see if they were safe.

Parents and guardians of North Park Elementary School students wait at Cajon High School to pick up their children Mon., April 10, 2017, in San Bernardino, Calif. AP

Marina Ramos told news station KABC-TV that she rushed to the school to try to pick up her grandson after she heard about the shooting. She said she spoke to him and he told her he was safe but was upset.

“He was crying. He’s scared,” she said. “It was a typical morning and then chaos broke out.”

“This is just tragedy,” said William Green, whose son attends the school. “This is not a good time right now, it’s just not. I grew up in this area ... man, this tough right now, I don’t even have the words to speak it right now.”

“It’s traumatizing. My eyes are just shaking,” another parent said. “I’m at a loss for words.”

San Bernardino Mayor R. Carey Davis said he was contacted by a White House spokesperson after the shooting.

Adrian Velasco, a 7-year-old student at North Park Elementary School, walks with his father, Hector, as Velasco’s mother, Raquel, raises her hands in relief after they were reunited at Cajon High School, Mon., April 10, 2017, in San Bernardino, Calif., after a deadly shooting occurred at the elementary school. AP

Burguan said earlier that there was a “large police response” to the incident. The motive for the incident is under investigation.

The city of 216,000 was the site of the December 2015 terror attack that killed 14 people and wounded 22 others at a meeting of San Bernardino County employees. Husband-and-wife shooters Syed Rizwan Farook and Tashfeen Malik were killed in a gunbattle with authorities later that day.

The city is known for its high rates of violent crime, especially homicides, and has struggled to emerge from bankruptcy.

The San Bernardino City Unified School District said the elementary school will be closed on Tuesday and Wednesday.