
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check If 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
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p:contains(Video)").css("background-color", "blue"); }); </script> </head> <body> <h1>Tutorialspoint</h1> <p>This is demo text.</p> <p>Free Tutorials</p> <p>Free Video Tutorials</p> </body> </html>
Advertisements