I currently have a problem with JavaScript and HTML. I want to edit the text of the button without removing the image which is in the same element. The line I want to edit:
<a href="warenkorb.html" class="artikel"><img src="warenkorb.png" height="25vh" id="warenkorb">Warenkorb</a>
What I have tried so far:
function warenAnzahl() {
var artikel = localStorage.getItem("artikel")
var x = document.getElementsByClassName("artikel")
var i;
if (artikel > 0) {
for (i = 0; i < x.length; i++) {
x[i].textContent = "Warenkorb (" + artikel + ")";
}
}
}
setInterval(warenAnzahl, 100)
The text gets changed how it should, but the image gets removed too with that method. Neither the text, nor the image, should move because it's already in my navbar.