diff --git a/packages/happy-dom/src/nodes/element/Element.ts b/packages/happy-dom/src/nodes/element/Element.ts index 8a34c7eae..6b9e57038 100644 --- a/packages/happy-dom/src/nodes/element/Element.ts +++ b/packages/happy-dom/src/nodes/element/Element.ts @@ -255,7 +255,15 @@ export default class Element extends Node implements IElement { * @returns Attributes. */ public get attributes(): INamedNodeMap { - return Object.assign(new NamedNodeMap(this), Object.values(this._attributes), this._attributes); + const nodeMap = new NamedNodeMap(this); + return new Proxy(nodeMap, { + get: (target, name) => { + return target[name] || ( + typeof name === "string" || typeof name === "number" + ? this._attributes[name] : undefined + ); + } + }) } /**