blob: 0842d6d2fec8acf6c7d127f8fd12fc24dd61182c [file] [log] [blame]
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:web/web.dart';
extension ElementAppendChildren on Element {
Element appendChildren(Iterable<Node> nodes) {
for (final node in nodes) {
this.appendChild(node);
}
return this;
}
removeChildren() {
while (true) {
var child = childNodes.item(0);
if (child == null) {
break;
}
removeChild(child);
}
return this;
}
Element setChildren(Iterable<Node> nodes) {
removeChildren();
appendChildren(nodes);
return this;
}
}
HTMLElement toggleClass(HTMLElement element, String classMember) {
if (element.className.contains(classMember)) {
element.className = element.className.replaceAll(classMember, '');
} else {
element.className += classMember;
}
return element;
}