JavaScript split function not working in IE

I am using the split function in JavaScript. It works fine in Firefox and Chrome, but IE displays an error when I call the split function. Is there a way to use another function like split?

+5
javascript internet-explorer
Jun 21 '11 at 8:25
source share
3 answers

separation method

It is fully supported by IE8

separation method for JScript 5.6

It is also fully supported by IE6.

Live example using .split(/\s+/)

Tested in IE9 standards, IE9 mode IE8, IE9 mode IE7 and IE9 quirks mode. Everyone is working.

Edit:

Turns out your actual problem is using .textContent . This does not work in IE. There are two alternatives.

Feature Detection:

 var str; if (el.textContent) { str = el.textContent; } else { str = el.innerText; } 

.nodeValue:

var str = el.nodeValue;

+6
Jun 21 2018-11-11T00:
source share

When you split a number instead of String, Javascript throws - Object does not support this property.

Make sure you have the string value in var.

+1
Jul 10 '13 at 17:55
source share

At least one difference between IE below # 9 and most other browsers when splitting strings is

var s = 'In some browsers, you can β€œsplit” a string on a parameterized delimiter and return the β€œsplit” bits in an array.';

 s.split(/( ?['"] ?)/).join('\n') /***************************************************/ Firefox 4.0.1>> In some browsers, you can " split " a string on a parenthized delimeter and return the " split-off " bits in the array. /***************************************************/ MSIE 8.0>> In some browsers, you can split a string on a parenthized delimeter and return the split-off bits in the array. /***************************************************/ MSIE 9.0>> In some browsers, you can " split " a string on a parenthized delimeter and return the " split-off " bits in the array. 
0
Jun 21 '11 at 12:45
source share



All Articles