Why bar magnets always attract objects made of iron,cobalt and nickel rather than gold,silver?
The magnetic properties of a material are governed entirely by the configuration of the electrons in that material. In metals there are two types of electrons: bound electrons and free electrons. The free electrons are free to move between atoms, and are the cause of conductivity in metals. The bound electrons are stuck to the individual atoms.
Each electron, in addition to having charge, also has a “magnetic moment” which is a fancy way of saying that it’s a tiny bar magnet. Generally the bound electrons will be paired off in opposite spin pairs. This is like putting a North-South magnet next to a South-North magnet. They almost completely cancel each other out. However, sometimes (in iron, nickel, and cobalt for example) you’ll have one or more un-paired electrons. The magnetic fields of these electrons aren’t canceled out by another, oppositely-oriented, electron. As such they lend an overall magnetic field to the atom they inhabit.
So, some metals are attracted to magnets because they are full of tinier magnets. Those tinier magnets twist about so that they align with the field of the larger magnet.