Magnets attract iron due to the influence of their magnetic field upon the iron. Before a piece of iron enters the magnetic field of a magnet, the polarization of the iron atoms is random. When exposed to the magnetic field, the atoms begin to align their electrons with the flow of the magnetic field, which makes the iron magnetized as well. This, in turn, creates an attraction between the two magnetized objects. This is why a piece of iron that is exposed to a magnet becomes magnetic for some time afterward.