- 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 does CSS Selectors work in jQuery?
The jQuery library supports nearly all of the selectors included in Cascading Style Sheet (CSS) specifications 1 through 3, as outlined on the World Wide Web Consortium's site.
Using jQuery library developers can enhance their websites without worrying about browsers and their versions as long as the browsers have JavaScript enabled.
Most of the JQuery CSS Methods do not modify the content of the jQuery object and they are used to apply CSS properties on DOM elements.
To apply any CSS property using jQuery method css( PropertyName, PropertyValue ).
Here is the syntax for the method −
selector.css( PropertyName, PropertyValue );
Here you can pass PropertyName as a JavaScript string and based on its value, PropertyValue could be string or integer.
Example
You can try to run the following code to learn how CSS Selectors work in jQuery:
<html> <head> <title>The jQuery Example</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function() { $("li").eq(2).css("color", "red"); }); </script> </head> <body> <div> <ul> <li>list item 1</li> <li>list item 2</li> <li>list item 3</li> <li>list item 4</li> <li>list item 5</li> <li>list item 6</li> </ul> </div> </body> </html>
- Related Articles
- How does jQuery.add( ) work in jQuery?
- How does jQuery.filter() method work in jQuery?
- How does jQuery.find() method work in jQuery?
- How does jQuery.eq() method work in jQuery?
- How does jQuery.map() method work in jQuery?
- How does jQuery.slice() method work in jQuery?
- How does jQuery.nextAll() method work in jQuery?
- How does jQuery.clone() method work in jQuery?
- How does jQuery replaceWith() method work?
- How does jQuery Datepicker onchange event work?
- What are jQuery Selectors?
- How to use JavaScript variables in jQuery selectors?
- Universal Selectors in CSS
- Type Selectors in CSS
- Descendent Selectors in CSS
