This is because you used
.textContent to set the text to
"<span>" + totalItems + "</span>".
The docs for textContent state: "... the text is not parsed as HTML ... Moreover, this avoids an XSS attack vector.".
You might want to use
.innerHTML instead, but be cautions as it can make your site vulnerable to cross-site scripting.