<html>
<head>
<script>
function debug(str) {
    text = document.createTextNode(str);
    debugDiv = document.getElementById('debugDiv');
    div = document.createElement('div');
    div.appendChild(text);
    debugDiv.appendChild(div);
}

function runTest() {
    if (window.testRunner) { 
        testRunner.dumpAsText();
    }
    var div = document.getElementById("foo");
    for (var i = 0; i < 5; ++i) {
        var span = document.createElement("span");
        span.appendChild(document.createTextNode(i));
        span.setAttribute("id", "bar");
        div.insertBefore(span, div.firstChild);
    }

    if (document.getElementById("bar").innerHTML == 4)
        debug("Success");
    else
        debug("Failure");
}
</script>
</head>
<body onload="runTest()">
This tests that getElementById returns the first element in document order when there are multiple ids. Bug 12988.
<div style="display:none" id="foo">text</div>
<div id='debugDiv'>
</div>
</body>
</html>
