diff --git a/_templates/todo.html b/_templates/todo.html
index 7f2609b97c7d991cd2795e8e351983cab335a4d6..d2f21803b19a5d6a858f4540cd17417f6146bec5 100644
--- a/_templates/todo.html
+++ b/_templates/todo.html
@@ -26,7 +26,7 @@
     var todoItems = document.getElementsByClassName('admonition-todo');
     var todolist = document.getElementById('todolist')
 
-    if(todoItems.length == 0) {
+    if(todoItems.length == 0 || !todoItems[0].hasAttribute('id')) {
         modalfortodoitemsparent.remove();
     } else  {
         for (var i = 0; i < todoItems.length; ++i) {