#NEWLINE# def insertChild( parent , toAdd , index ) : #NEWLINE# #INDENT# count = 0 #NEWLINE# child = parent . firstChild #NEWLINE# before = None #NEWLINE# while child : #NEWLINE# #INDENT# if ( child . nodeType == 1 ) : #NEWLINE# #INDENT# if ( count == index ) : #NEWLINE# #INDENT# before = child #NEWLINE# break #NEWLINE# #UNINDENT# count += 1 #NEWLINE# #UNINDENT# child = child . nextSibling #NEWLINE# #UNINDENT# if ( before is None ) : #NEWLINE# #INDENT# parent . appendChild ( count ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# parent . insertBefore ( toAdd , before )