user3634523
user3634523

Reputation: 13

How do I remove a space before a comma with jQuery?

Date format for a field displays as "January 1 , 2000" (for example).

I would like to remove the extra space before the comma using jQuery. I tried this but it does not seem to work:

$('.field-item:contains(" , ")').html().replace(' ,' , ',');

Upvotes: 1

Views: 220

Answers (1)

Adam Pietrasiak
Adam Pietrasiak

Reputation: 13194

You change value that is returned but you do not assing it back to item. Use:

var field = $('.field-item:contains(" , ")');
var newValue = field.html().replace(' ,' , ',');
field.html( newValue ); //assing it back

So it's working like (http://api.jquery.com/html/)

item.html(); //returns value
item.html(newVal); //changes value

Upvotes: 1

Related Questions