A magnet, comprising: - a body that comprises a first and a second section (104,105) made of magnetic material for directing magnetic flux to an object to be attached, the first and the second section being separated and attached to a third section of the body, which third section is made of non-magnetic material, and - a slide that comprises a permanent magnet, and a first and a second pole piece attached to opposite magnetic pole surfaces of the permanent magnet, the slide being arranged to be movable relative to the body between a first and a second position in order to alter the path of the magnetic flux generated by the permanent magnet; characterised in that: - the first section comprises a through hole having a first and a second through hole portion (108,109) the diameter of the first through hole portion being smaller than the diameter of the second through hole portion, - a first end of the through hole is closed by a fourth section of the body and a second end of the through hole is closed by the second and the third section of the body, so that a cavity consisting of a first and a second cavity portion is formed inside the body, - the slide is arranged inside the cavity so as to be movable in the longitudinal direction of the through hole, the first pole piece being directed towards the first end of the through hole, and - the magnet comprises means for transferring a medium into and out of the first and the second cavity portion in order to move the slide; wherein at the first position of the slide, the permanent magnet, at least part of the first pole piece and at least part of the second pole piece are located inside the first through hole portion, and at the second position of the slide, at least part of the first pole piece is located inside the first through hole portion and the second pole piece is located outside the first through hole portion. - a body that comprises a first and a second section (104,105) made of magnetic material for directing magnetic flux to an object to be attached, the first and the second section being separated and attached to a third section of the body, which third section is made of non-magnetic material, and - a slide that comprises a permanent magnet, and a first and a second pole piece attached to opposite magnetic pole surfaces of the permanent magnet, the slide being arranged to be movable relative to the body between a first and a second position in order to alter the path of the magnetic flux generated by the permanent magnet; - the first section comprises a through hole having a first and a second through hole portion (108,109) the diameter of the first through hole portion being smaller than the diameter of the second through hole portion, - a first end of the through hole is closed by a fourth section of the body and a second end of the through hole is closed by the second and the third section of the body, so that a cavity consisting of a first and a second cavity portion is formed inside the body, - the slide is arranged inside the cavity so as to be movable in the longitudinal direction of the through hole, the first pole piece being directed towards the first end of the through hole, and - the magnet comprises means for transferring a medium into and out of the first and the second cavity portion in order to move the slide;