3

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!

asked Oct 25, 2012 at 12:08

2 Answers 2

8

Try this,

Live Demo

First part

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

Second part

str = $.trim($('.label_im_getting').text().split(':')[1]);
VisioN
146k35 gold badges287 silver badges291 bronze badges
answered Oct 25, 2012 at 12:09
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! The only thing was that I wanted the second half of the split, so (using @alex23 's response), I switched the index to get the second half. Thanks!
4
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.
answered Oct 25, 2012 at 12:13

1 Comment

Thank you for the quick and awesome response! I choose @Adil 's solution as it utilizes jQuery more, but this answer gives me the background to what is actually happening behind the scenes and how to manipulate it. Thank you!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.