From 184fcbeb7a3258627d27e23285d6d1e9277e3d91 Mon Sep 17 00:00:00 2001 From: sammizheng Date: Thu, 7 Nov 2024 21:59:38 +0800 Subject: [PATCH] fix: check the priority value of the existing property --- lib/CSSStyleDeclaration.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/CSSStyleDeclaration.js b/lib/CSSStyleDeclaration.js index b43b9af..798d46d 100644 --- a/lib/CSSStyleDeclaration.js +++ b/lib/CSSStyleDeclaration.js @@ -46,13 +46,24 @@ CSSOM.CSSStyleDeclaration.prototype = { this[this.length] = name; this.length++; } + + // If the priority value of the incoming property is "important", + // or the value of the existing property is not "important", + // then remove the existing property and rewrite it. + if (priority || !this._importants[name]) { + this.removeProperty(name); + this[this.length] = name; + this.length++; + this[name] = value + ''; + this._importants[name] = priority; + } } else { // New property. this[this.length] = name; this.length++; + this[name] = value + ''; + this._importants[name] = priority; } - this[name] = value + ""; - this._importants[name] = priority; }, /**