If I grab some html from one element, then attempt to assign it as the text content of another element, newlines are not preserved (at least not in the latest Firefox and Chromium).
So, for example, the follow code (with sensible html) produces output where the newlines are replaced by spaces. Well, except the alert, which works as expected.
$("#info").data("html", $("#info").html());
$("#jquery").text($("#info").data("html"));
document.getElementById("javascript").textContent = $("#info").data("html");
$("#alert").click(function() { alert($("#info").data("html")) });
Here's a running example: http://jsfiddle.net/76S7z/2/
There should be some method of setting the html of one element as the text of another while preserving newlines properly.
Is this possible with "text" or "textContent"? Is there an alternative way to do this? Is there a simple workaround? A less than simple workaround?
`. – Felix Kling Jan 10 '14 at 00:15
's with something temporarily and the switch them back after you move the text/html. Also depending on what type of element you are moving it into will depend on how you can get your line breaks back. – Jan 10 '14 at 00:25
"). – Jan 10 '14 at 00:28
`'s with actual newline characters? – Felix Kling Jan 10 '14 at 00:55