views:

23

answers:

3

I have a string that is dynamically entered into:

<span class="note_message">The order was manually edited:<br/>The list of edits goes here, and this maybe somewhat long sometimes</span>

That is an example of a string that may be entered into the span. It ALWAYS starts with "The order was manually edited:", so I would like to use jQuery to see if the string contains those words at the beginning and if so, to select the rest of the string after "The order was manually edited:" and save it into a separate variable.

How can I go about doing that?

A: 

I believe that only help jQuery can provide you is with selecting the span.

and then its values.

jQuery('.note_message').val();

Rest you can use simple javascript string functions like indexOf to check if the values contains your matching text.

var x = jQuery('.note_message').val();
if(x.indexOf('yuor matching text')!=-1)

to perform what you need

sushil bharwani
A: 

You can retrieve the text of an element with text() -- this will recursively gather all text within an element:

var text = $('.note_message').text();

Then, you can remove the bit you don't want:

text = text.replace(/^The order was manually edited:/, '');
text; // => "The list of edits goes here, and this ..."
J-P
+1  A: 

Try this:

var Str=$(".note_message").filter(function(){
  return $(this).text().match(/^The order was manually edited\:/);
}).text().replace(/The order was manually edited\:/,'');

Here's the code in action.

Gert G