1

I have a script that when clicked will copy the contents of a div to the clipboard

<script type="text/javascript">
var program=document.getElementById('code');
ShowLMCButton(program.innerHTML, '', '', './static/js/lmcbutton.swf');
</script>

But when I click "Copy" it copies

<p>Line 1<br />Line 2</p>

Is there anyway to copy it like this:

Line 1 Line 2

MK.
  • 31,408
  • 15
  • 67
  • 104
Blease
  • 1,186
  • 3
  • 33
  • 58

3 Answers3

1

Sounds like you want the innerText instead of innerHTML?

MK.
  • 31,408
  • 15
  • 67
  • 104
1

You can use textContent or innerText. The differences, according to MDN, are:

  • Note that while textContent gets the content of all elements, including <script> and <style> elements, the mostly equivalent IE-specific property, innerText, does not.
  • innerText is also aware of style and will not return the text of hidden elements, whereas textContent will.
  • As innerText is aware of CSS styling, it will trigger a reflow, whereas textContent will not.
bfavaretto
  • 69,385
  • 15
  • 102
  • 145
  • innerText doesn't work for me? And as for textContent, the value is strung across one line. The idea for this is to click copy and then to paste it into notepad, to share VB scripts. – Blease Oct 02 '12 at 22:26
  • `innerText` works for me (in Chrome, OSX), and it replaces the `
    ` with `\n`. `textContent` does in fact join the contents into a single line. http://jsfiddle.net/542AF/
    – bfavaretto Oct 02 '12 at 22:32
0

You are using an external library, so you should refer to the library documentation.

Anyway, there is a related post here.

Community
  • 1
  • 1
adripanico
  • 1,038
  • 14
  • 31