Make sure getElementById always returns the first element with the given ID in tree order.(fixes #1822)
Update register_named_element using binary search