I have some very basic Javascript that copies text upon the push of a button. My problem is that it doesnt preserve line breaks:
First off, the element doesn't preserve line breaks. You can use the
element instead. Since your HTML may contain
elements instead of line break characters, I would also suggest using jQuery to prepend \r\n
before each
.
function copyToClipboard(element) {
var text = $(element).clone().find('br').prepend('\r\n').end().text()
element = $('
Type to edit
this text