$('textarea').on('keyup', function(){
var ths = $(this);
var array = $(this).val().split(' ');
array.forEach(function(value){
if (value.match(/(threewords)/g)) {
ths.val().select(value);
}
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea>word twowords threewords</textarea>
What I want to do is to select
the matching text
inside the textarea
if it matches the .match(/(threewords)/g)
if I wrote word
,
The problem is that I keep getting that .match()
is null
if there is no match or getting select is not a function
if the match exists, But nothing is selected and the error occurs, How can I do what i'm trying to do properly?