The permanent magnet within the electromagnet sits behind a copper coil with an iron core, and when electricity is applied, the copper coil creates a magnetic field that redirects the permanent magnet and ‘cancels’ out the external magnetic field.
eBay