I have three paragraphs <p>and I want to show their value idin textarea, and this is the code I used:
var pNodesList = document.getElementsByTagName('p');
var text = "";
var pArrayList = Array.prototype.slice.call(pNodesList);
pArrayList.forEach(function(value, index){
text += value.getAttribute('id') + String.fromCharCode(13);
});
document.getElementsByTagName('textarea')[0].value = text;
The problem is when I click on this button, this is the result that I get in my textarea:
myP1
null
myP2
null
myP3
Why am I getting these null values?
Edit:
This is my HTML:
<p id="myP1" style="font-weight:bold;">
Ceci est une paragraphe avec deux balises <ul>
<br>
<ul>Liste 1 : </ul>
<ul>Liste 2 : </ul>
</p>
<p id="myP2" style="font-weight:bold;">
Ceci est une paragraphe avec une balise <ul>
<br>
<ul>Liste 3 : </ul>
</p>
<p id="myP3" style="font-weight:bold;">Ceci est une paragraphe simple.</p>
source
share