I have this simple html:
<h3 id='target'>
<p> <!--insert javascript joined array here ---> </p>
</h3>
And this simple Javascript:
var letters = ["a", "b", "c", "d"];
var joinedLetters = letters.join(", and ");
var getElement = document.getElementById("target").firstElementChild;
getElement.innerHTML = joinedLetters;
PROBLEM:
It comes out formatted in h3 (text bold) and not p. My object is to insert the joined array in the paragraph element. I don't know if it's possible. Any help/explanation is appreciated. Thanks!
UPDATE:
I usually catch that mistake, but I guess not that time. Thanks all! I made all the necessary changes:
<h3>Joined</h3>
<p id='target'><!--insert joined array here--></p>
And the JS (not including the array JS above). This seems to be the outcome I wanted:
var getElement = document.getElementById("target").innerHTML;
document.write(getElement = joinedLetters);
CURIOUS:
How come if I write the code above like this, a duplicate of the array will appear?:
var getElement = document.getElementById("target");
document.write(getElement.innerHTML = joinedLetters);
And, it seems that the inserted array is not editable by CSS (all links established):
p {color: red}
I'm thinking it has something to do with the document.write function. Thanks once again! Great help, great help! :)
FINAL ANSWER:
var getElement = document.getElementById("target");
getElement.innerHTML = joinedLetters;
This house is clean.
<code>was doing there. :)<p>in an<h3>in the first place? It makes no semantic sense. Why not move the<p>out of the<h3>give it its own id and target that?