Problem: I have a list with Items and I want to add the sum of all list-items to the h1-element.
I am trying to do that by adding additional html via javascript. You can see that in those 10 lines of js-code.
The first console.log(newHeading.textContent) returns "undefined". Why is that? Is that because I am not creating a separate em-Element as parent-node to the text (which is only the respective sum of list-items)?
The 2nd console.log returns the title + html + item-sum, even though I used text.Content. Why is that?
This is what it looks like so far: Codepen
/* add item-counter to header
*
*/
var heading = document.getElementById("title"); // fetching the h1-Element in a Variable
var headingText = heading.firstChild.nodeValue; // saving the text alone separately,
// which is "Shopping-List"
var totalItems = listItems.length; // saving the number of Items
// creating a new Title, by adding an em-Element to the previously saved "headingText"
var newHeading = headingText + '<em id="subTitle">' + totalItems + '</em>';
console.log(newHeading.textContent); // this retuns "undefined"
heading.textContent = newHeading;
console.log(heading.textContent); // this returns the Title-Text + Item-Sum + parent-em-
// node. I thought .textContent ***hides the html***?