Search code examples
javascriptdojo

Create <p> element inside existing div in Dojo


I have a <div> element that already exists in my HTML document. I would like to dynamically add <p> elements to it using Dojo.

I am confused about domConstruct create vs. place vs toDom methods. I don't want to create more divs, I just want to place a paragraph element inside the existing div.

How would I go about doing this?

Currently I have this but it doesn't seem to be working I'm assuming because the create method is used to create divs rather than other types of elements :

var errorPopup = dom.byId('error-dialog');
for (var i = 0; i < errorMessages.length; i++) {
                      var eMessage = domConstruct.create("<p>'"+errorMessages[i]+"'</p>");
                      errorPopup.appendChild(eMessage);
                  }

Solution

  • I'm still not entirely sure why the create method doesn't work (unless my original hunch is correct) but I got it to work with the place method.

    for (var i = 0; i < errorMessages.length; i++) {
                          var eMessage = domConstruct.place("<p>'"+errorMessages[i]+"'</p>", "error-dialog");
                      }