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

3 Answers 3

2

Sounds like you want the innerText instead of innerHTML?

Sign up to request clarification or add additional context in comments.

Comments

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.

2 Comments

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.
innerText works for me (in Chrome, OSX), and it replaces the <br> with \n. textContent does in fact join the contents into a single line. jsfiddle.net/542AF
0

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

Anyway, there is a related post here.

1 Comment

Try this plugin, better that the flash based: archive.plugins.jquery.com/project/copy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.