The diagram shows a closed switch connected in the electric circuit for an electromagnet. The closed switch allows the electric current from the battery to flow through the solenoid (coil of wire around the nail) and back to the opposite end of the battery.
When an electric current passes through a wire, a magnetic field is created around the wire. The magnetic field can be visualized as circles expanding outward, much like the pattern of ripples on water.
The coiled wire of the solenoid compressed the magnetic field, thus producing a concentrated (stronger) magnetic field inside the coils. Since the magnetic field is created by an electric current, the magnetic effect inside the coil is called an electromagnet.
The iron nail is inside the coil, thus the magnetic effect can be more easily used to attract magnetic materials, such as metal paper-clips.
The magnetic field of the solenoid causes the tiny magnetic domains (groups of atoms) in the metal to be aligned in one direction (all the north poles point the same way). Magnetic domains act much like tiny magnets. When these “tiny magnets” point in the same direction the nail becomes magnetized. The magnetic effect of the nail plus the magnetic effect of the solenoid creates a magnet strong enough to pick up magnetic objects.