0
How can I concatenate two values in the same appendchild?
For example, transform this
li.appendChild(_nomeAutorTexto);
li.appendChild(_sobrenomeAutorTexto);
therein
li.appendChild(_nomeAutorTexto + espaço + _sobrenomeAutorTexto);
Here the whole code:
const listaTextos = document.querySelector("#lista-textos");
function renderLista (doc) {
let li = document.createElement("li");
let _nomeAutorTexto = document.createElement("span");
let _sobrenomeAutorTexto = document.createElement("span");
let _nomeTexto = document.createElement("span");
let _livroTexto = document.createElement("span");
li.setAttribute("data-id", doc.id);
_nomeAutorTexto.textContent = doc.data().nomeAutorTexto;
_sobrenomeAutorTexto.textContent = doc.data().sobrenomeAutorTexto;
_nomeTexto.textContent = doc.data().nomeTexto;
_livroTexto.textContent = doc.data().livroTexto;
li.appendChild(_nomeAutorTexto);
li.appendChild(_sobrenomeAutorTexto);
li.appendChild(_nomeTexto);
li.appendChild(_livroTexto);
listaTextos.appendChild(li);
}
This is a simple matter of syntax or do I have to do some more sophisticated trick?
If you have all the code?
– novic
Hi Virgilio: I just put :-)
– LuizC
For example: if you put only one text in Li I think you don’t need to create two
spam
or this data will be formatted withcss
or are they just texts? or is there something to take this information to develop something.?– novic
The end, what is your goal? From what I understand, your code is working. You just want to summarize these lines of
appendChild()
?– LipESprY
See your doubt seems not to have, because I’m not seeing problems in this code, just can’t concatenate elements.
– novic
@Virgilionovic, the code works, I just wish the messages _name Authorext and _name Authorext were on the same line ...
– LuizC
Create the values in an element! why? o
appendChild
only accepts one element at a time it works like this, it was done like this. the maximum of merging the two information into only one element.– novic
That’s right, @Lipespry: I’d like the links _Name Authorext and _Name Authorextext to be in the same appendchild() ...
– LuizC
In that case, my answer is valid again. It cannot. Of course you can get the same result of its function in numerous ways, but it has no relation to your question. As @Virgilionovic mentioned: you can put everything into a single element. Only it will change the final result.
li
will have a singlespan
with all texts "concatenated".– LipESprY
Whoa, coming to light! I could concatenate the information in that part of the code, so that the content of _nameAuthorText includes tb _last nameAuthorText? _nameAuthoritText.textContent = (doc.data().nameAuthoritText + oc.date().last nameAuthoritText) ?
– LuizC
That’s exactly what @Virgilionovic suggested: "- Create values in an element!" Note only that you change the final result. As he himself mentioned: "- If you are going to put only one text in Li do you think you do not need to create two spam or these data will be formatted with css or are only text even? or is there something to take this information to develop something.?"
– LipESprY
Thanks, people, I will study a little more to implode the suggestion of @Virgilionovic. Gratefully!
– LuizC
If solved, the solution should be in the form of an answer, not an edition of the question;
– Woss
Thanks for the touch, @Andersoncarloswoss.
– LuizC