
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
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 −
Advertisements