Fix the JS so that it actually works.

Kudos to http://en.uncyclopedia.co/wiki/User:Bizzeebeever for suggesting
this approach, which, no doubt, is far saner than my initial attempt at
fixing this.

So why was this broken in the first place? I have no idea to be honest. It
used to work at some point, I'm sure of that. What's a part of the problem
is that there are many components, lots of similar IDs and DOM structures
and many different pieces using similar concepts.

Change-Id: Ieeb1218bd6d28f7973f2a87ed0f64e99c4553254