I have 5 instructions in 5 different lines, inside of a for statement: for(var i = 0; i < this.subTabArr.length ; i++){ $.get("subtab.html #subDiv", function(html){ $("#left").append(html); });
/** PROBLEM CODE START**/ $("#subDiv").css({top: lastTop}); $("#subDiv").attr("id", "" + this.subTabArr[i].attName); $("#subImg").attr("id", "img" + this.subTabArr[i].attName); $("#subText").text("" + this.subTabArr[i].name); $("#subText").attr("id", "txt" + this.subTabArr[i].attName); /** PROBLEM CODE END **/ } ------------- <div id="subDiv" class="subselected"> <img id="subImg"></img> <label id="subText"></label> </div> ------------ When I execute the function that contains them it doesn't work (It doesn't change subDiv's position and basically stacks all the div's together), but when I debug it and execute it step by step, it works perfectly. Any ideas of how can I avoid this? It looks like the next instruction is running before the previous one can end, but I have absolutely no idea of how to stop this from happening. Thanks in advance.