Race in javascript nested in html format