I try this:
form['ment'] = '<blockquote>test</blockquote><a href="#">test</a> <Your reply here>';
if($(form['ment']).search('<Your reply here>'))
alert(1)
else
alert(0)
But have this error:
TypeError: $(formment).search is not a function
I fix this problem that:
if(form['ment'].value.search('<Вашият отговор тук>') != -1)
alert(1)
else
alert(0)
I try this:
form['ment'] = '<blockquote>test</blockquote><a href="#">test</a> <Your reply here>';
if($(form['ment']).search('<Your reply here>'))
alert(1)
else
alert(0)
But have this error:
TypeError: $(form.ment).search is not a function
I fix this problem that:
if(form['ment'].value.search('<Вашият отговор тук>') != -1)
alert(1)
else
alert(0)
Share
Improve this question
edited Sep 24, 2012 at 13:10
Michael Berkowski
271k47 gold badges450 silver badges394 bronze badges
asked Sep 16, 2012 at 14:20
DefenseDefense
2594 silver badges21 bronze badges
5
- Did you include the jquery js file? – rekire Commented Sep 16, 2012 at 14:22
- Yes, I include jquery.js file – Defense Commented Sep 16, 2012 at 14:24
-
1
search
is the method of String, not jQuery object. – xdazz Commented Sep 16, 2012 at 14:24 - …and it does search for regular expressions, not for substrings – Bergi Commented Sep 16, 2012 at 16:48
-
Rather than edit the title with
[RESOLVED]
or similar, mark the correct answer as accepted by clicking the checkmark beside it. – Michael Berkowski Commented Sep 24, 2012 at 13:10
2 Answers
Reset to default 3What you want is $(form['ment']).text().search()
So:
form = [];
form['ment'] = '<blockquote>test</blockquote><a href="#">test</a> <Your reply here>';
if(form['ment'].search('<Your reply here>') != -1)
alert(1)
else
alert(0)
Here's a working example.
To find out that is matching string to other you don't need jQuery!.
var ment = "<blockquote>test</blockquote><a href="#">test</a> <Your reply here>",
search = "<Your reply here>";
ment.indexOf( search ) != -1; // indexOf returns -1 when search does not match
/<Your reply here>/.test( ment ); // returns true when search is in ment.