- 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 .class Selector
The .class selector in jQuery is used to select all elements with the specific class.
Syntax
The syntax is as follows −
$(".class")
Above, the parameter class specify the class of the elements.
Example
Let us now see an example to implement the jQuery .class selector −
<!DOCTYPE html> <html> <head> <style> .one { background-color: blue; color: white; font-size: 18px; border: 2px blue dashed; } </style> <script src="https://code.jquery.com/jquery-3.4.1.js"></script> <script> $(document).ready(function(){ $(".demo").addClass("one"); }); </script> </head> <body> <h1>Heading One</h1> <h2>Heading Two</h2> <p class="demo">Demo text 1...</p> <p>Demo text 2...</p> <p class="demo">Demo text 3...</p> <p>Demo text 4...</p> </body> </html>
Output
This will produce the following output −
- Related Articles
- How to combine a class selector and an attribute selector with jQuery?
- jQuery :button Selector
- jQuery :checkbox Selector
- jQuery :checked Selector
- jQuery :contains() 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

Advertisements