Changed pure js trim function for jquery equivalent.