Theory:

Action of magnets:
When two magnets are moved close to each other, they either attract or repel each other.
The opposite poles of magnets attract, whereas the similar poles of magnets repel when they are pulled towards each other.
Attraction or repulsion of the magnets depends on the direction of the poles facing each other.
 
magn.png
Attraction and repulsion of magnets
Repulsion occurs when like poles (N-N or S-S) of the magnets are kept closer to each other.
Attraction occurs when unlike poles (N-S or S-N) of the magnets are kept closer to each other.
Loss of magnetic property:
The magnetic property of a material will be lost if they are
  • heated,
  • hammered,
  • dropped from a certain height, or
  • due to improper storage.
Precautions to retain the magnetic property:
The bar magnets should always be kept in pairs separated by a piece of wood keeping the unlike poles on the same side.
 
store mag.svg
Piece of wood placed between bar magnets
 
A piece of iron is kept across the poles for a horseshoe magnet.
 
horseshoeMagnet.png
Piece of iron at the end of horseshoe magnet
 
The magnets should be kept away from the electronic gadgets like cassettes, mobiles, television, music system, compact disks (CDs) and the computer. All the electronic gadgets will have magnets in it. When a magnet is placed near these gadgets, it affects magnetic property, and hence spoils the device and the magnet.