A novel photo-cross-linkable nanofiber based on a uracil-functionalized polymer, poly[1-(4-vinylbenzyl uracil)] (PVBU), was prepared using the electrospinning technique. This PVBU nanofiber can be converted into a covalent network nanofiber through exposure to UV light at a wavelength of 254 nm. This PVBU nanofiber is able to distinguish and selectively remove mercury ions (Hg2+) from other metal ions in aqueous solution. The maximum Hg 2+ adsorption capacity of the PVBU nanofiber is 543.9 mg g -1, which is significantly higher than that of cyclic imide derivatives. The improved adsorption of Hg2+ allows a detection limit of less than 1 ppm, which has rarely been achieved for Hg2+ sensing. Furthermore, the PVBU fiber can be reused for 10 consecutive cycles using 1.0 M HCl treatment. This new material has significant potential for the simultaneous detection and separation of Hg2+ in environmental and industrial fields.