-4
In my function below, it works perfectly in relation to the src
from the image, it brings the image based on example1.png, example2.png... But when printing in innerHTML (I also tested with innerText), it doesn’t print the value of the variable, it writes in html "text1", "text2", and "text3", when in fact I need the value of them. Is there any way to make this work?
const text1 = "bla"
const text2 = "bla bla"
const text3 = "bla bla bla"
function blaBla(foo) {
elemento.src = `images/"exemplo" + ${foo} + ".png"`
elemento2.innerHTML = `"text" + ${foo}`
}
botao.onclick = () => {
blaBla("1");
}
botao2.onclick = () => {
blaBla("2");
}
botao3.onclick = () => {
blaBla("3");
}
The identifier
var
is a identifier reserved by the interpreter do not use it as a variable. See here a discussion about the problem and the use of reserved words as an identifier. Make the correction in your example.– Augusto Vasques
It would also be nice if you put HTML in the question to form a [MCVE]. Directly you can not do what you want to do but there are alternatives that do not use.
– Augusto Vasques