I have a part of JavaScript that is designed to dynamically create a nested div set in my application. The parent div is created just fine, but the inner div is not a rendering at all.
Any help would be great!
JavaScript:
function createWindow() { var note_window = document.createElement("div"); note_window.setAttribute("id", "note_window"); note_window.setAttribute("class", "notification-window"); note_window.style.visibility = 'visible'; var title = document.createElement("div"); title.setAttribute("id", "title"); title.setAttribute("class", "col-md-12"); title.innerHTML = "Notifications"; note_window.appendChild(title); var navbar = document.getElementById("navbar"); navbar.appendChild(note_window); }
Highlighted HTML:
<div id="note_window" class="notification-window" style="visibility: visible;"> Text </div>
Desired HTML:
<div id="note_window" class="notification-window" style="visibility: visible;"> Text <div id="title" class="col-md-12"> More Text </div> </div>
EDIT:
Thanks for the help, I partially answered my question ...
Further in my code there is another function that edits the contents of note_window.
if (document.getElementById("note_window") == null) { createWindow(); if (getNotifications() == null) { note_window.innerHTML = "Text" } }
When I comment on the code for installing innerHTML, both divs render correctly ... Now the question is ... Why ??
source share