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'),
    str;

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!

Comments

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 *

3x4x5w