Use jQuery for all the things

Generate HTML attributes and contents with jQuery so things are escaped
properly. Also use 'this' in the each() callback, and prefix variables
that contain jQuery objects with $.