This is due to electrolysis which is the passage of an electric current through an ionic substance that is eitherr molten or dissolved in a suitable solvent, thus resulting in chemical reactions at the electrodes and seperation of materials.
Hope this is of some help. :)
Hope this is of some help. :)