A generalization of Cayley's theorem