0

Possible Duplicate:
InnerText alternative in mozilla

I have this code

<div id="code">My program<br />It is here!</div>
<script type="text/javascript">
var program=document.getElementById('code');
ShowLMCButton(program.innerText);
</script>

It works in IE but in firefox, innerText does not work. How can I use this in firefox? I have tried .text() but it doesn't want to work! I need the text to be in the form "My program\n It is here!" It can't be textContent because that copies the html tags.

What this is, is to copy a VB script from a site and paste it straight into a program and it must include all the new lines, white space etc.

ShowLMCButton() is a script that is "Click to Copy" - http://www.lettersmarket.com/view_blog/a-3-copy_to_clipboard_lmcbutton.html

Community
  • 1
  • 1
Blease
  • 1,380
  • 4
  • 38
  • 64

2 Answers2

3

use textContent for firefox

ShowLMCButton(program.innerText || program.textContent)
YogeshWaran
  • 2,291
  • 4
  • 24
  • 32
2

You can use JQuery to do this:

Live Demo

ShowLMCButton($('#code').text());
Adil
  • 146,340
  • 25
  • 209
  • 204
  • It copies the text, it just doesn't copy the returns and the white space like innerText does – Blease Oct 15 '12 at 17:28
  • @josh it gives spaces as well. http://jsfiddle.net/rajaadil/WS7G3/ – Adil Oct 15 '12 at 17:32
  • It does, but I want the contents to be copied to the clipboard using the LMCButton script and then pasted into notepad with the new lines too, which your answer does not do – Blease Oct 15 '12 at 18:11
  • See this: http://jsfiddle.net/WS7G3/1/ Try it in firefox and paste into notepad and then in IE and paste into notepad. See the difference? – Blease Oct 15 '12 at 18:18