I thought of adding this as comment, but made me to post. "Please use jQuery and save your time from these type of issues."
if happen to use jQuery
in near future.
$(document).on('click', '.class', function() {
// code here
});
There is a good compatability
script on this page below. Just copy and paste it into your script.
http://dochub.io/#javascript/function.bind