I'm sure I'm missing something silly here, but I cannot seem to figure it out.
I am basically trying to get the names from my database, which is working fine (I can show them on screen), but when I try to get them and store them in a variable, it doesn't work.
here's the code:
<% if(data.length){
for(var i = 0;i < data.length;i++) { %>
<p id="names"><%= data[i].FULLNAME %></p>
<% }
}else{ %>
<p>nothing</p>
<% } %>
<script>
var listOfNames = document.getElementById("names").value
console.log("list of names" + listOfNames)
I now need a new line after every name, instead of beside each other one by one, like so:
thanks for the help in advanced.
You need to use innerText
instead of value
const listOfNames = document.getElementById("names").value console.log("list of names: " + listOfNames) const correctText = document.getElementById("names").innerText console.log("list of names: " + correctText)
<p id="names">whatever</p>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.