I created and added pre element with contentEditable attribute. I inserted some text with non-breaking space and tried to get text and split using simple txt.split(/\s/), where txt represent string from pre element. Unfortunately, this split doesn’t work well in IE7 and return wrong splitted data in array when string contains non-breaking spaces.

I solved this problem by using little trick:

var temp = doc.createElement('div'),

temp.innerHTML = txt;
str = temp.innerText || temp.textContent || temp.text;
temp = null;

and then:

var newString = str.split(/\s/);

Variable txt contains original string from pre element. After this little trick the split works well. Cheers!


You can leave a response, or trackback from your own site.

Before you add comment see for rules.

Leave a Reply

Your email address will not be published. Required fields are marked *