An earthquake can strike almost anywhere at any time, given the right circumstances. They're most commonly caused by tectonic plates shifting, and this results in vibrations under our feet that can be powerful depending on the magnitude of movement.
While some earthquakes are nothing more than a small vibration beneath your feet, other larger ones have been known to level buildings and cause casualties.
For the most part, you want to avoid being near things that are going to fall and collapse on you. Avoiding power lines, walls, trees, bridges, and other things that have a potential to fall on you is a good idea.
You shouldn't stay inside of door frames, because they're not built as strong today as they once were and it could collapse on you. Instead, if you're inside, seek cover under a table or desk and cover your head with your hands.
If you're outside, to try to get to an open area where you're free of power lines, trees, and other hazards. Being somewhere where nothing can fall on you increases your chances of survival.
You may even consider building a safety kit if you're in an earthquake-prone area like California so that you're ready to respond when one hits by surprise.