streetlight
streetlight

Reputation: 5968

Parsing Text with jQuery

I'm attempting to parse a text string with jQuery and to make a variable out of it. The string is below:

Publications Deadlines:   armadllo

I'm trying to just get everything past "Publications Deadlines: ", so it includes whatever the name is, regardless of how long or how many words it is.

I'm getting the text via a the jQuery .text() function like so:

$('.label_im_getting').text()

I feel like this may be a simple solution that I just can't put together. Traditional JS is fine as well if it's more efficient than JQ!

Upvotes: 3

Views: 10816

Answers (2)

Adil
Adil

Reputation: 148180

Try this,

Live Demo

First part

str = $.trim($('.label_im_getting').text().split(':')[0]);

Second part

str = $.trim($('.label_im_getting').text().split(':')[1]);

Upvotes: 8

flavian
flavian

Reputation: 28511

var string = input.split(':') // splits in two halfs based on the position of ':'
string = input[1] // take the second half
string = string.replace(/ /g, ''); // removes all the spaces.

Upvotes: 4

Related Questions