assert_equals(removed,null,"should not get removed element.");
},"Document.getElementById with a script-inserted element");
test(function(){
vargBody=document.body;
// setup fixtures.
varTEST_ID="test3";
vartest=document.createElement("div");
test.setAttribute("id",TEST_ID);
gBody.appendChild(test);
// update id
varUPDATED_ID="test3-updated";
test.setAttribute("id",UPDATED_ID);
vare=document.getElementById(UPDATED_ID);
assert_equals(e,test,"should get the element with id.");
varold=document.getElementById(TEST_ID);
assert_equals(old,null,"shouldn't get the element by the old id.");
// remove id.
test.removeAttribute("id");
vare2=document.getElementById(UPDATED_ID);
assert_equals(e2,null,"should return null when the passed id is none in document.");
},"update `id` attribute via setAttribute/removeAttribute");
test(function(){
varTEST_ID="test4-should-not-exist";
vare=document.createElement('div');
e.setAttribute("id",TEST_ID);
assert_equals(document.getElementById(TEST_ID),null,"should be null");
document.body.appendChild(e);
assert_equals(document.getElementById(TEST_ID),e,"should be the appended element");
},"Ensure that the id attribute only affects elements present in a document");
test(function(){
vargBody=document.body;
// the method should return the 1st element.
varTEST_ID="test5";
vartarget=document.getElementById(TEST_ID);
assert_not_equals(target,null,"should not be null");
assert_equals(target.getAttribute("data-name"),"1st","should return the 1st");
// even if after the new element was appended.
varelement4=document.createElement("div");
element4.setAttribute("id",TEST_ID);
element4.setAttribute("data-name","4th");
gBody.appendChild(element4);
vartarget2=document.getElementById(TEST_ID);
assert_not_equals(target2,null,"should not be null");
assert_equals(target2.getAttribute("data-name"),"1st","should be the 1st");
// should return the next element after removed the subtree including the 1st element.
target2.parentNode.removeChild(target2);
vartarget3=document.getElementById(TEST_ID);
assert_not_equals(target3,null,"should not be null");
assert_equals(target3.getAttribute("data-name"),"4th","should be the 4th");
},"in tree order, within the context object's tree");
test(function(){
varTEST_ID="test6";
vars=document.createElement("div");
s.setAttribute("id",TEST_ID);
// append to Element, not Document.
document.createElement("div").appendChild(s);
assert_equals(document.getElementById(TEST_ID),null,"should be null");
},"Modern browsers optimize this method with using internal id cache. This test checks that their optimization should effect only append to `Document`, not append to `Node`.");
test(function(){
vargBody=document.body;
varTEST_ID="test7"
varelement=document.createElement("div");
element.setAttribute("id",TEST_ID);
gBody.appendChild(element);
vartarget=document.getElementById(TEST_ID);
assert_equals(target,element,"should return the element before changing the value");
element.setAttribute("id",TEST_ID+"-updated");
vartarget2=document.getElementById(TEST_ID);
assert_equals(target2,null,"should return null after updated id via Attr.value");