Electromagnets operate on the magnetic effect of electric current.
Electromagnets are not the same as permanent magnets.
Electromagnets are made of wire coils that have electricity running through them.
Moving charges generate magnetic fields, so when an electric current flows through the coils of wire in an electromagnet, the coils behave like magnets.
When the electricity is turned off, the coils cease to function as magnets.