jQuery detect if string contains something
You get the value of the textarea, use it :
$('.type').keyup(function() {
var v = $('.type').val(); // you'd better use this.value here
if (v.indexOf('> <')!=-1) {
console.log('contains > <');
}
});
use Contains of jquery Contains like this
if ($('.type:contains("> <")').length > 0)
{
//do stuffs to change
}
You can use javascript's indexOf function.
var str1 = "ABCDEFGHIJKLMNOP";
var str2 = "DEFG";
if(str1.indexOf(str2) != -1){
alert(str2 + " found");
}
You could use String.prototype.indexOf
to accomplish that. Try something like this:
$('.type').keyup(function() {
var v = $(this).val();
if (v.indexOf('> <') !== -1) {
console.log('contains > <');
}
console.log(v);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea class="type"></textarea>
Update
Modern browsers also have a String.prototype.includes
method.