Do you mean you want to put all this in some .js file that can be used on various pages? So the code has to search for the <div class="foo"> and <div class="bar"> and so on divs and attach the onclick handler to each one, appropriately?
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.