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

2 Comments

@niteshguptav63
niteshguptav63 Nov 17, 2024 at 1:39 PM

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

@niteshguptav63
niteshguptav63 Nov 16, 2024 at 10:56 AM

When will I get my course?

@admin79
admin79 Nov 17, 2024 at 1:29 PM

Now, Your query was resolved.

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support