An electromagnet is a temporary magnet that behaves like a magnet when an electric current is passed through the copper wire and loses its magnetism when the current is stopped.
The battery is a source of electrons. When you connect the wire to the battery, the electrons flow through the wire.
Electromagnets are created by wrapping a copper wire around an iron nail and running current through the wire. The electric field in the wire coil creates a magnetic field around the nail.