How can I have jQuery check to see if the content of a variable contains a specific word and have it execute an alert if matched?
if( str.indexOf( "your word" ) !== -1 )
or
if( str.search( /your regex/ig ) )
or
if( str.match( /your regex/ig ).length > 0 )
As it shows, you do not need jQuery to solve this problem.
But, hell, why not use jQuery selectors if you want:
$('#someId:contains(text)')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With