2

This is my 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!"

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 etc.

dsgriffin
  • 66,495
  • 17
  • 137
  • 137
Blease
  • 1,380
  • 4
  • 38
  • 64

5 Answers5

2

You used the tag , so I assume that you use jQuery. Hence you have to refer to the jQuery object and not the HTMLObject.

<div id="code">My program<br />It is here!</div>
<script type="text/javascript">
    var program = $('#code');
    ShowLMCButton(program.text());
</script>
h2ooooooo
  • 39,111
  • 8
  • 68
  • 102
2

you could check for the browser’s feature support to use the correct property accordingly.

var program=document.getElementById('code');
if(document.all){
     ShowLMCButton(program.innerText);
} else{
     ShowLMCButton(program.textContent);
}

document.all will basically determines if the browser is IE (Microsoft extension to the W3C-standard)

Rorchackh
  • 2,113
  • 5
  • 22
  • 38
2

innerText is not supported by FireFox as you say. I found innerHTML to be a good solution to this problem.

From: document.getElementById('<%= LblMapLat.ClientID %>').innerText To: document.getElementById('<%= LblMapLat.ClientID %>').innerHTML

0

innerText doesn't work in firefox . if you can , use innerHTML . and if can't , you can use textContent . you should do this , to work with firefox and IE simultaneous :

ShowLMCButton(program.innerText||program.textContent);
mrReiha
  • 908
  • 6
  • 24
  • this will give appended result chrome where both the properties will work.. – logan Sep 02 '13 at 13:53
  • @logan when you use ' || ' if first property ( or anything else ) is available , use that , and if it isn't , use second property ; therefore that hasn't any problem . i tested a code here: [link](http://notepad.cc/ciadiesca97) ;) – mrReiha Nov 15 '13 at 19:48
  • Why did you give me down vote? – mrReiha May 06 '15 at 11:33
  • you can't ask people who downvoted as it is unknown.. – logan May 18 '15 at 10:54
  • I didn't ask who, I asked why; If there is any problem here, it's better me to know that. I'm using this approach usually. – mrReiha May 18 '15 at 11:00
0

Use, textContent which will work in Firefox and IE as well..

logan
  • 7,946
  • 36
  • 114
  • 185