- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
jQuery :contains() Selector
The :contain() selector in jQuery is used to select elements containing the specified text.
Syntax
The syntax is as follows −
$(":contains(text)")
Here, the parameter text is the text to find. The same elements are selected with the specified text.
Example
Let us now see an example to implement the :contains() selector −
<!DOCTYPE html> <html> <head> <style> .one { color: brown; background-color: orange; font-size: 16px; border: 2px blue dashed; } </style> <script src="https://code.jquery.com/jquery-3.4.1.js"></script> <script> $(document).ready(function(){ $("p:contains(the)").addClass("one"); }); </script> </head> <body> <h1>Examination</h1> <p>Timings: 10AM - 1PM</p> <p>The examination hall details would be emailed to the students.</p> </body> </html>
Output
This will produce the following output −
- Related Articles
- How to pass a variable into a jQuery attribute-contains selector?
- jQuery :button Selector
- jQuery :checkbox Selector
- jQuery :checked Selector
- jQuery :disabled Selector
- jQuery :empty Selector
- jQuery :enabled Selector
- jQuery :even Selector
- jQuery :file Selector
- jQuery :first Selector
- jQuery :focus Selector
- jQuery :gt() Selector
- jQuery :header Selector
- jQuery :hidden Selector
- jQuery :image Selector

Advertisements