I am working on a program to diplay the bubble sort step by step. I wanted to use setTimeout() but for that even my DOM functions are unresolved. However I am unable to figure it out. Can anybody help me out with this code?

Code:
function bubbleSort(items){
list=str_array; 
  var len = list.length - 1;
for(var loop = 0; loop <list.length; loop++)   
					{
						var button=document.createElement("button");
						ID = "myButton"+loop;
					button.setAttribute("id",ID);
						button.style.backgroundColor= "HotPink"; 
						button.classList.add('linearStyle');
						document.body.appendChild(button);
					}
    for (var i = 0; i < len ; i++) {
        for (var j = 0, swapping, endIndex = len - i; j < endIndex; j++) {
            comparisons++;
            if (str_array[j] > str_array[j + 1]) {
     document.getElementById("myButton"+i).innerHTML=list[j];
                swapping = list[j];
                list[j] = list[j + 1];
            list[j + 1] = swapping;
                swaps++;
       document.getElementById("myButton"+i).innerHTML=list[j]; 
			};
        };
    }
	
}