jquery - Copying content of a div to a new window adds extra unwanted new line -


i use code copy contents of div show in new window

     var w = window.open();      var text = $("#my-div").html();      $(w.document.body).html(text); 

but along content, adds new lines, around 200px before content.

what might reason ?

for empty body:

<body> </body>  $(document.body).html()  --> `"↵↵↵"` 

so, if need avoid empty lines use trim():

 var w = window.open();  var text = $("#my-div").html().trim();  $(w.document.body).html(text); 

trim(): removes whitespace both ends of string. whitespace in context whitespace characters (space, tab, no-break space, etc.) , line terminator characters (lf, cr, etc.).


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -