refactor and use append to generate the box div in html page