File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,19 @@ public function removeAttribute(string $name)
176176 }
177177
178178
179+ /**
180+ * Unsets element's attributes.
181+ * @return static
182+ */
183+ public function removeAttributes (array $ attributes )
184+ {
185+ foreach ($ attributes as $ name ) {
186+ unset($ this ->attrs [$ name ]);
187+ }
188+ return $ this ;
189+ }
190+
191+
179192 /**
180193 * Overloaded setter for element's attribute.
181194 */
@@ -564,7 +577,7 @@ final public function attributes(): string
564577 $ tmp = null ;
565578 foreach ($ value as $ k => $ v ) {
566579 if ($ v != null ) { // intentionally ==, skip nulls & empty string
567- // composite 'style' vs. 'others'
580+ // composite 'style' vs. 'others'
568581 $ tmp [] = $ v === true ? $ k : (is_string ($ k ) ? $ k . ': ' . $ v : $ v );
569582 }
570583 }
Original file line number Diff line number Diff line change @@ -177,3 +177,14 @@ test(function () { // isset
177177 Assert::true (isset (Html::el ('a ' )->setAttribute ('id ' , '' )->id ));
178178 Assert::false (isset (Html::el ('a ' )->setAttribute ('id ' , null )->id ));
179179});
180+
181+
182+ test (function () { // removeAttributes
183+ $ el = Html::el ('a ' )->addAttributes (['onclick ' => '' , 'onmouseover ' => '' ]);
184+ Assert::true (isset ($ el ->onclick ));
185+ Assert::true (isset ($ el ->onmouseover ));
186+
187+ $ el ->removeAttributes (['onclick ' , 'onmouseover ' ]);
188+ Assert::false (isset ($ el ->onclick ));
189+ Assert::false (isset ($ el ->onmouseover ));
190+ });
You can’t perform that action at this time.
0 commit comments