fixed an error in javascript that happened on handling clicks in document