Skip to content
Related Articles
Open in App
Not now

Related Articles

How to add CSS properties to an element dynamically using jQuery ?

Improve Article
Save Article
  • Last Updated : 24 Mar, 2021
Improve Article
Save Article

In this article, we will see how to add some CSS properties dynamically using jQuery. To add CSS properties dynamically, we use css() method. The css() method is used to change style property of the selected element. 

The css() method can be used in different ways. This method can also be used to check the present value of the property for the selected element:



Here we have created two elements inside body tag i.e. <h1> and <h3> elements. We apply CSS property on <body> tag and <h1> tag using css() method dynamically.



<!DOCTYpe html>
        How to add CSS properties to an
        element dynamically using jQuery?
    <script src=
        $(document).ready(function () {
            $("body").css("text-align", "center");
            $("h1").css("color", "green");
        How to add CSS properties to an element
        <br>dynamically using jQuery?


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!