diff --git a/pyscriptjs/src/python/pyscript.py b/pyscriptjs/src/python/pyscript.py
index a9fcfda3..eb1fd890 100644
--- a/pyscriptjs/src/python/pyscript.py
+++ b/pyscriptjs/src/python/pyscript.py
@@ -250,7 +250,7 @@ class Element:
child = js.document.createElement("div")
self.element.appendChild(child)
- if self.element.children:
+ if append and self.element.children:
out_element = self.element.children[-1]
else:
out_element = self.element
diff --git a/pyscriptjs/tests/integration/test_02_display.py b/pyscriptjs/tests/integration/test_02_display.py
index ad7fbecb..05825a6d 100644
--- a/pyscriptjs/tests/integration/test_02_display.py
+++ b/pyscriptjs/tests/integration/test_02_display.py
@@ -219,6 +219,31 @@ class TestOutput(PyScriptTest):
pattern = r'