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
streetlight
5,97813 gold badges66 silver badges103 bronze badges
2 Answers 2
Try this,
First part
str = $.trim($('.label_im_getting').text().split(':')[0]);
Second part
str = $.trim($('.label_im_getting').text().split(':')[1]);
Sign up to request clarification or add additional context in comments.
1 Comment
streetlight
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!
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
flavian
28.6k11 gold badges68 silver badges107 bronze badges
1 Comment
streetlight
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!
lang-js