I need to set each element of array entered in input from new line, i trued to do it likes this join("\\n") - didn't work for me. How can i do it properly
Here is my code
var inp = document.getElementById("inp");
var btn = document.querySelector(".btn");
var list = document.querySelector('#list');
var arr = [];
btn.addEventListener('click', function(str) {
var valInp = inp.value;
arr.push(valInp);
inp.value = "";
list.innerHTML = arr.join(" ");
});
use <br />
instead of \\n
list.innerHTML = arr.join('<br />');
\\n
is a new line character .
<br />
is an HTML element for a line break .
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.