Matt Elhotiby
Matt Elhotiby

Reputation: 44066

putting an underscore in its place

how do I take the string using jQuery

Standard Class

and turn it into this

Standard_Class

if this is the id

$('#some_id').text;

Upvotes: 0

Views: 72

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038780

Why do everything needs to be done with jQuery? How about a regex:

var result = 'Standard Class'.replace(/\s/g, '_');

and to modify the text into an existing element jQuery could be useful:

$('#some_id').text($('#some_id').text().replace(/\s/g, '_'));

Upvotes: 4

Related Questions