Water is diamagnetic as well as a dielectric. Being diamagnetic means that when an external magnetic field is applied, the water creates its own magnetic field perpendicular to the applied magnetic field. Diatomic oxygen and hydrogen are not magnetic, but single atoms of these elements do carry a charge and therefor would interact with a magnetic field. It is this interaction that make hydrogen form on one electrode and oxygen on the other.