A magnet has a north pole and a south pole. A north side will attract to a south side but a north and north or south and south side will push away from each other. There are two different types of magnets, permanent magnets and electromagnets. Permanent magnets hold their magnetic force for a long time. Bar magnets and horseshoe magnets are an example of permanent magnets.
Electric currents flowing through wire can also cause magnetic fields.
This is called electromagnets. If the battery isn't plugged in then the flow stops. Electromagnets also have north and south poles. The force of the electromagnet depends on the number of turns in the coil and force of current. When an iron rod is placed inside the coil of an electromagnet the force becomes more powerful.