Fixed append process in Javascript