Like this:

if (str.indexOf("Yes") >= 0)

...or you can use the tilde operator:

if (~str.indexOf("Yes"))

This works because indexOf() returns -1 if the string wasn't found at all.

Note that this is case-sensitive.
If you want a case-insensitive search, you can write

if (str.toLowerCase().indexOf("yes") >= 0)

Or:

if (/yes/i.test(str))

The latter is a regular expression or regex.

Regex breakdown:

  • / indicates this is a regex
  • yes means that the regex will find those exact characters in that exact order
  • / ends the regex
  • i sets the regex as case-insensitive
  • .test(str) determines if the regular expression matches str To sum it up, it means it will see if it can find the letters y, e, and s in that exact order, case-insensitively, in the variable str
Answer from SLaks on Stack Overflow
🌐
SitePoint
sitepoint.com › blog › javascript › jquery string contains functions
jQuery String Contains Functions — SitePoint
February 13, 2024 - Finding whether a string contains another string can be achieved not using jQuery but plain ole JavaScript! Using the str.indexOf() function and str.search().
🌐
jQuery
api.jquery.com › contains-selector
:contains() Selector | jQuery API Documentation
Categories: Selectors > Content Filter | Selectors > jQuery Extensions · Description: Select all elements that contain the specified text. text: A string of text to look for.
🌐
W3Schools
w3schools.com › jsref › jsref_includes.asp
W3Schools.com
The includes() method returns true if a string contains a specified string.
🌐
jQuery
api.jquery.com › jQuery.contains
jQuery.contains() | jQuery API Documentation
The $.contains() method returns ... nodes are supported; if the second argument is a text or comment node, $.contains() will return false. Note: The first argument must be a DOM element, not a jQuery object or plain JavaScript object....
🌐
W3Schools
w3schools.com › jquery › sel_contains.asp
jQuery :contains() Selector
jQuery Overview jQuery Selectors jQuery Events jQuery Effects jQuery HTML/CSS jQuery Traversing jQuery AJAX jQuery Misc jQuery Properties ... The :contains() selector selects elements containing the specified string.
🌐
C# Corner
c-sharpcorner.com › article › search-word-or-substring-from-paragraph-or-string-using-javascript-and-jquery
Check If String Contains Substring In JavaScript
May 5, 2023 - In this case, we will use the contains() Method in jQuery to find the single or multiple paragraphs which contain the desired word or substring.
Find elsewhere
🌐
O'Reilly
oreilly.com › library › view › jquery-and-javascript › 9780133410877 › ch02lev2sec12.html
Checking to See If a String Contains a Substring - jQuery and JavaScript Phrasebook [Book]
December 17, 2013 - Content preview from jQuery and ... way to check to see if one string is a substring of another is to use .indexOf(substring) on the main string....
Author: Brad Dayley
Published: 2013
Pages: 384
🌐
Edureka Community
edureka.co › home › community › categories › web development › jquery › jquery string contains check
JQuery string contains check | Edureka Community
June 15, 2022 - I need to check whether a string contains another string or not? var str1 = "ABCDEFGHIJKLMNOP"; var ... do I use to find out if str1 contains str2?
🌐
GeeksforGeeks
geeksforgeeks.org › jquery › jquery-contains-selector
jQuery :contains() Selector - GeeksforGeeks
July 11, 2025 - The jQuery :contains() selector in jQuery is used to select elements containing the specified string.
🌐
Amebaownd
oseroute.amebaownd.com › posts › 43187671
Jquery string contains | drewsaapharcougerc1989's Ownd
April 30, 2023 - In this tutorial, we discussed the basics of strings in JavaScript. If you’re looking to learn more
🌐
Google
developers.google.com › identity › protocols › oauth2 › javascript-implicit-flow
OAuth 2.0 for Client-side Web Applications | Google for Developers
August 7, 2026 - If the user does not approve the request, the response contains an error message. The access token or error message is returned on the hash fragment of the redirect URI, as shown in the following examples: ... In addition to the access_token parameter, the fragment string also contains the token_type parameter, which is always set to Bearer, and the expires_in parameter, which specifies the lifetime of the token, in seconds.
🌐
jQuery
api.jquery.com › jQuery
jQuery() | jQuery API Documentation
Description: Accepts a string containing a CSS selector which is then used to match a set of elements. ... A DOM element to wrap in a jQuery object.
🌐
Squash
squash.io › how-to-check-if-a-string-contains-a-substring-in-javascript
How To Check If A String Contains A Substring In Javascript
August 25, 2023 - One of the simplest and most straightforward ways to check if a string contains a substring in JavaScript is by using the includes() method.
🌐
Cloudflare
developers.cloudflare.com › turnstile › get-started › client-side-rendering
Embed the widget · Cloudflare Turnstile docs
June 17, 2026 - When you embed a Turnstile widget inside a <form> element, an invisible input field with the name cf-turnstile-response is automatically created. This field contains the verification token and gets submitted with your other form data.
🌐
GeeksforGeeks
geeksforgeeks.org › jquery › how-to-check-a-string-starts-ends-with-a-specific-string-in-jquery
How to check a string starts/ends with a specific string in jQuery ? - GeeksforGeeks
July 12, 2025 - JavaScript search() method: It checks whether a particular string is contained in another string and returns the starting index of that substring.
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-check-whether-a-string-contains-a-substring-in-javascript.php
How to Check Whether a String Contains a Substring in JavaScript
// Check if the substring exists ... else{ alert("Substring not found!"); } </script> In ES6 you can use the includes() method to check if a contains a substring....
🌐
jQuery Mobile
demos.jquerymobile.com › 1.0a1 › experiments › api-viewer › docs › jQuery.contains › index.html
jQuery.contains()
Description: Check to see if a DOM node is within another DOM node · containerThe DOM element that may contain the other element