tags:

views:

21

answers:

2

Is is possible remove all content before a specific string with jquery? For instance say I wanted to strip all the text before the word "subcommittee" in this example below. How would I do that?

With losses mounting among hoteliers, fishermen and others whose livelihoods have been curtailed by the spill, frustration is "rapidly escalating" along the Gulf Coast alive."

Linn told a House Energy and Commerce subcommittee Monday that the amount of money BP has paid local residents for their losses has typically been about $5,000, a sum he dismissed as "a marketing ploy." Businesses such as his vacation rental company are borrowing money to pay their overhead costs, which he called "the only way we're going to keep our business alive."

+1  A: 

you dont need jquery for this... but ill play along

var text = $("#myText").text();
text = text.substring(text.indexOf("subcommittee"));
$("#myText").text(text);

something like that.

mkoryak
The second param to `.substring()` is optional ;)
Nick Craver
yeah i couldnt remember which part omitting it would chop off, so i left it there
mkoryak
+1  A: 

Just use indexOf() to find out the position of the given string in the text and use substring() to get a piece of the text from the given position on.

var text = element.text();
var filtered = text.substring(text.indexOf('subcommittee'));
BalusC