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!

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

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 *

6e4e1p