I've created the below function to
dynamically create HTML elements and append them wherever I want. The console doesn't log any errors when it runs, but the second element (<p>)
doesn't write to the document.
I'm thinking the error is something related to the "createdDiv" variable, but I haven't been able to isolate what is going wrong.
Any help would be greatly appreciated!
//Array of elements to be created
var createdElements = [
[ 'div', 'Class0', 'ID0'],
['p', 'Class1', 'ID1']
];
//function to create and append elements to document
function createHTML( typeOfCreatedElement ,createdElementClass, createdElementId, locationForCreatedElement ){
var createdElement = document.createElement( typeOfCreatedElement );
createdElement.className = createdElementClass;
createdElement.id = createdElementId;
locationForCreatedElement['appendChild']( createdElement );
return createdElement;
}
//run function 2x;
//createdDiv successfully writes to the document, but createdParagraph disappears into a black hole...
var createdDiv = createHTML( createdElements[0][0], createdElements[0][1], createdElements[0][2], document.body );
var createdParagraph = createHTML( createdElements[1][0], createdElements[1][1], createdElements[1][2], createdDiv );