To explain the code a little bit, the while loop will continue as long as the condition is true. So, when "document.getElementById('SelectDiv'+divID)" is in the condition it will return True if the element exists. So, starting at 1, the loop will continue incrementing divID until there is no div with the ID of "'SelectDiv'+divID"