Can someone shed some light on the behavior of javascript getElementById() when there are elements with duplicate IDs in HTML DOM??
Yes, the behaviour is undefined.
The markup is invalid, and there is no standard that defines what the browser should do in that situation.
Each browser will try to do something reasonable, usually return the first element. Other possible ways that it could be handled would be to return the last element, no element at all (null), or throw an error.