how do I strip white space when grabbing text with jQuery?
str=str.replace(/^\s+|\s+$/g,'');
Actually, jQuery has a built in trim function:
var emailAdd = jQuery.trim($(this).text());
See here for details.
Use the replace
function in js:
var emailAdd = $(this).text().replace(/ /g,'');
That will remove all the spaces
If you want to remove the leading and trailing whitespace only, use the jQuery $.trim method :
var emailAdd = $.trim($(this).text());
Javascript has built in trim:
str.trim()
It doesn't work in IE8. If you have to support older browsers, use Tuxmentat's or Paul's answer.