How to check whether a string contains a substring in jQuery?

The jQuery :contains() Selector is used to check whether a string contains a substring in jQuery.

Set the substring you are searching for in the contains() method as shown below:

$(document).ready(function(){
   $("p:contains(Video)").css("background-color", "blue");
});

Now, let us see the complete code to check whether a string contains a substring or not:

Example



   
   



Tutorialspoint

This is demo text.

Free Tutorials

Free Video Tutorials

Updated on: 2026-03-11T22:50:41+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements