summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-25 18:52:03 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-25 18:52:03 +0100
commit632cc53e2c02b05993458115baeb44cf6a0702ec (patch)
tree2847298640b12f47af50d733234616ba6d66e072
parent1146ab0fae03ea7b6f812606bb69a11d5e161434 (diff)
downloadserenity-632cc53e2c02b05993458115baeb44cf6a0702ec.zip
LibWeb: Add ParentNode::remove_all_children()
This safely removes all children from a Node.
-rw-r--r--Libraries/LibWeb/DOM/ParentNode.cpp10
-rw-r--r--Libraries/LibWeb/DOM/ParentNode.h2
2 files changed, 12 insertions, 0 deletions
diff --git a/Libraries/LibWeb/DOM/ParentNode.cpp b/Libraries/LibWeb/DOM/ParentNode.cpp
index 3bc86e480d..7042dcaa86 100644
--- a/Libraries/LibWeb/DOM/ParentNode.cpp
+++ b/Libraries/LibWeb/DOM/ParentNode.cpp
@@ -26,3 +26,13 @@
#include <LibWeb/DOM/ParentNode.h>
+namespace Web {
+
+void ParentNode::remove_all_children()
+{
+ while (RefPtr<Node> child = first_child()) {
+ remove_child(*child);
+ }
+}
+
+}
diff --git a/Libraries/LibWeb/DOM/ParentNode.h b/Libraries/LibWeb/DOM/ParentNode.h
index e8e826c959..cc86505a8e 100644
--- a/Libraries/LibWeb/DOM/ParentNode.h
+++ b/Libraries/LibWeb/DOM/ParentNode.h
@@ -35,6 +35,8 @@ public:
template<typename F> void for_each_child(F) const;
template<typename F> void for_each_child(F);
+ void remove_all_children();
+
protected:
explicit ParentNode(Document& document, NodeType type)
: Node(document, type)