Modifying CSS Using Query

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 210:- Modifying CSS Using Query

In jQuery, the css() method can be used to modify CSS properties of an element. The method takes two parameters - the CSS property name and the value to be set.

Here is an example that changes the background color of all paragraphs to yellow:

htmlCopy code

<!DOCTYPE html> <html> <head> <title>jQuery Example</title> <style> p { background-color: blue; color: white; padding: 10px; } </style> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { $("p").css("background-color", "yellow"); }); </script> </head> <body> <p>This is a paragraph.</p> <p>This is another paragraph.</p> </body> </html>

In the above example, the $(document).ready() function is used to make sure that the script is executed only after the document has finished loading. The $ function is used to select the paragraphs, and the css() method is used to set the background color to yellow.

You can also pass an object with multiple CSS properties and their values to the css() method. Here is an example that sets the background color and font size of all paragraphs:

htmlCopy code

<!DOCTYPE html> <html> <head> <title>jQuery Example</title> <style> p { background-color: blue; color: white; padding: 10px; } </style> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { $("p").css({ "background-color": "yellow", "font-size": "20px" }); }); </script> </head> <body> <p>This is a paragraph.</p> <p>This is another paragraph.</p> </body> </html>

In this example, an object is passed to the css() method with the CSS properties and their values to be set. The properties and values are separated by a colon (:), and each property-value pair is separated by a comma.

24. Jquery

Comments: 2

profile
@niteshguptav63
17-Nov-2024, 01:39 PM

I am not able to access videos from second class and further. I have already completed first class

profile
@niteshguptav63
16-Nov-2024, 10:56 AM

When will I get my course?

profile
@admin79
17-Nov-2024, 01:29 PM

Now, Your query was resolved.

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?