- 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
How jQuery selects elements using CSS?
jQuery uses CSS selector to select elements using CSS. Let us see an example to return a style property on the first matched element. The css( name ) method returns a style property on the first matched element.
Here is the description of all parameter used by this method −
- name − The name of the property to access.
Example
You can try to run the following code to learn how jQuery selects elements with CSS:
<html> <head> <title>jQuery Example</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> $(document).ready(function() { $("div").click(function () { var color = $(this).css("background-color"); $("#result").html("That div is <span style = 'color:" + color + ";'>" + color + "</span>."); }); }); </script> <style> div { width:60px; height:60px; margin:5px; float:left; } </style> </head> <body> <p>Click on any square:</p> <span id = "result"> </span> <div style = "background-color:blue;"></div> <div style = "background-color:gray;"></div> <div style = "background-color:#123456;"></div> <div style = "background-color:#f11;"></div> </body> </html>
- Related Articles
- Selects all elements with CSS
- Selects all elements inside elements with CSS
- Selects specific elements like with CSS
- Selects all elements and all elements with CSS
- Selects all elements with rel=”nofollow” with CSS
- Selects all elements with class="mydemo" with CSS
- Selects all elements with alt attribute with CSS
- Selects all elements that are placed immediately after elements with CSS
- How to manipulate CSS pseudo-elements ::before and ::after using jQuery?
- Selects all elements where the parent is a element with CSS
- How to change CSS using jQuery?
- Selects all elements with alt attribute containing the word "Tutorials" with CSS
- How to apply CSS properties using jQuery?
- How to apply CSS style using jQuery?
- Selects all elements with a lang attribute value starting with "en" with CSS

Advertisements