Reputation: 1420
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
Upvotes: 1
Views: 1060
Reputation: 1058
You are using an external library, so you should refer to the library documentation.
Anyway, there is a related post here.
Upvotes: 0
Reputation: 71939
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, whereastextContent
will.- As
innerText
is aware of CSS styling, it will trigger a reflow, whereastextContent
will not.
Upvotes: 1