javascript better, shorter and connected with top button