var vars = {}; var newCount = 0; $('.hello').click(function(){ newCount++; vars['hello' + newCount] = '<p>Hello World</p>'; console.log( JSON.stringify(vars) ); });