JQuery trim does not remove & nbsp ;?

How can I trim all spaces from a string even if they are caused by non-breaking spaces (  )

For instance:

var foo = $.trim($('<p>&nbsp;foo&nbsp;</p>').text());

Foo value " foo "instead"foo"

UPDATE So the problem was not a jQuery trim function. It works great. The problem is the MSAjax trim function. jQuery, by right, uses function detection and, if they do not exist, uses its implementation.

Unfortunately, the MSAJax trim implementation does not break char 160 (without a break). However, regex jQuery alignment does, as it understands that IE does not include char 160 in \ s.

Why do stupid browser problems always end up with M $ implementing something ???

+5
source share
3 answers

So the problem was not a jQuery trim function. It works great. The problem is the MSAjax trim function. jQuery, by right, uses function detection and, if they do not exist, uses its implementation.

Unfortunately, the MSAJax trim implementation does not break char 160 (without a break). However, regex jQuery alignment does, as it understands that IE does not include char 160 in \ s.

Why do stupid browser problems always end up with M $ implementing something?

+3
source

Are you sure about that? I tried a slightly modified version of your snippet:

var foo = $.trim($('<p>&nbsp;foo&nbsp;</p>').text());
alert('#' + foo + '#');

and there were no spaces on either side of "foo". http://jsfiddle.net/Ux7Wc/

This used jQuery 1.6.2 in Firefox 5.

+1

All Articles