Changing it to a regex with global modifier to do it for multiple lines and to separate the newline and carriage return. Your replace function searches for both characters after another and replace that, but often you wont have a carriage return.
var dataToAdd = document.getElementById("test").innerHTML.replace(/[\\n\\r]/g, "" ); console.log(dataToAdd);
<div id="test">1 2 3 </div>
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.