     return mArray[Int(index)]
   }
 
+  /**
+   * https://dom.spec.whatwg.org/#dom-htmlcollection-nameditem
+   */
   public func namedItem(name: DOMString) -> pElement? {
-    let index = mArray.indexOf({ return $0.getAttribute("id") == name})
-    if nil != index {
-      return mArray[index!]
+    // Step 1
+    if name.isEmpty {
+      return nil
     }
-    return nil
+
+    // Step 2
+    for element in mArray {
+      if element.getAttribute("id") == name ||
+         (element.namespaceURI != nil &&
+          element.namespaceURI! == Namespaces.HTML_NAMESPACE &&
+          element.getAttributeNS(nil, "name") == name) {
+        return element
+      }
+    }
+    return nil;
   }
 
   init() {}


  internal var mArray: Array<pElement> = []
  
  public var length: ulong {
    return ulong(self.mArray.count)
  }

  public func item(index: ulong) -> pElement? {
    if index >= self.length {
      return nil

 * 
 */

/**
 * https://dom.spec.whatwg.org/#interface-htmlcollection
 */
public class HTMLCollection: pHTMLCollection {

  internal func append(element: pElement) -> Void {
