From a2184526d862d7d738a087d4793baa35fe350619 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Fri, 20 Jul 2012 12:12:45 +0100 Subject: [PATCH] added a Node.clear() helper method so they can be cleared like collections --- libraries/stdlib/src/kotlin/dom/Dom.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libraries/stdlib/src/kotlin/dom/Dom.kt b/libraries/stdlib/src/kotlin/dom/Dom.kt index 226bf17a042..2d2d11fb025 100644 --- a/libraries/stdlib/src/kotlin/dom/Dom.kt +++ b/libraries/stdlib/src/kotlin/dom/Dom.kt @@ -246,7 +246,17 @@ class ElementListAsList(val nodeList: NodeList): AbstractList() { } - +/** Removes all the children from this node */ +fun Node.clear(): Unit { + while (true) { + val child = firstChild + if (child == null) { + return + } else { + removeChild(child) + } + } +} /** Returns an [[Iterator]] over the next siblings of this node */ fun Node.nextSiblings() : Iterator = NextSiblingIterator(this)