Various embodiments of the present invention are directed to switchable carboxybetaine-based polymers, hydrogels, and/or elastomers, along with novel related monomers, crosslinkers, and methods. Under acidic conditions, the materials undergo self-cyclization and can catch and kill bacteria. Under neutral/basic conditions, these materials undergo ring-opening and can release killed bacterial cells and resist protein adsorption and bacterial attachment. These smart polymers, hydrogels and elastomers also show excellent mechanical properties making them highly desirable for many biomedical applications.