0

Possible Duplicate:
jQuery text() call preserves newlines in Firefox but not in IE

I got some issues with this code in IE:

var frameFromValues = $('#getData').contents().find("body table tbody tr#c_"+ currencyFrom).text().split('\n');
console.log(frameFromValues);

Console in Chrome shows:

["", "          KRA", "          Fenix", "          1", "          1", "      "]

Console in IE 9 shows:

KRAFenix11

And because of that, when I try to get a value by its index like this:

cFrom = frameFromValues[5];

It says "Undefined" in IE, but it works perfectly fine in Chrome.

How do I make it work in IE?

Community
  • 1
  • 1
estrar
  • 1,373
  • 4
  • 12
  • 37
  • have a look at it http://stackoverflow.com/questions/2308134/trim-in-javascript-not-working-in-ie – Rahul Oct 31 '12 at 09:07
  • I've already added: String.prototype.trim = function() {return $.trim(this)} Gonna try the double quote. Edit: No luck with double quotes. I'll see if freakish link will help me clear it out. – estrar Oct 31 '12 at 09:09
  • 1
    http://stackoverflow.com/questions/656605/jquery-text-call-preserves-newlines-in-firefox-but-not-in-ie It's not about `split` ( which works correctly, try it in IE console ), it's about `text()` function. Basically IE skips `\n` and thus `split` returns one element array. – freakish Oct 31 '12 at 09:09
  • @freakish I tried to wrap the data within
     but that did not solve the problem.
    – estrar Oct 31 '12 at 09:46
  • @estrar Did you also try setting CSS rule `#div { white-space: pre }`? What version of IE we are talking about? – freakish Oct 31 '12 at 10:05
  • @freakish Sorry, I forgot to include the pre in the selector. Seems to work now! You could post it as an answer if you want the credit I suppose. – estrar Oct 31 '12 at 10:33
  • @estrar Cheers! I'm glad it is working. The solution is not mine, so I won't take any credit for it. :) – freakish Oct 31 '12 at 10:53

2 Answers2

0

Try removing the trim(); function

Adi
  • 5,089
  • 6
  • 33
  • 47
viruskimera
  • 193
  • 16
0

Instead of trim use:

cFrom = frameFromValues[5].replace(/^\s+|\s+$/g, ''); 
VicoMan
  • 289
  • 2
  • 13