How to display a one-time element on a page via JS?
-
& lt; div id = "block" & gt; & lt; / div & gt;
var block = document.getElementById('block'); var elem = document.createElement('p'); elem.textContent = 'one text'; block.appendChild(elem); elem.textContent = 'two text'; block.appendChild(elem);
This is the code that outputs:
two text
And I need the output to be:
one text
two text
That is, 2 paragraphs were created with different text but with the same variable nameJavaScript Aaron Farley, Jan 4, 2020 -
with different text but with the same variable name
I don’t know why you needed it this way:
var block = document.getElementById('block');
var elem = document.createElement('p');
elem.textContent = 'one text';
block.appendChild(elem);
var elem = document.createElement('p');
elem.textContent = 'two text';
block.appendChild(elem);Anonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!