How to apply CSS in a particular div element using jQuery ? Last Updated : 30 Jul, 2024 Comments Improve Suggest changes Like Article Like Report In this article, we will set the CSS of a div element using jQuery. We will use the CSS property to set the CSS.Approach: We will create a div element with some text and hyperlinks. Then we will use jQuery to apply CSS to the div element. jQuery comes with the function .css() where we can get and set CSS of any element. We will use it for the div element.Syntax:<script> $("div").css("css-property","value");</script>Example 1: Using a Simple CSSĀ HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> <!-- Include jQuery file using CDN link--> <script src= "https://code.jquery.com/jquery-3.6.0.min.js"> </script> </head> <body> <!-- Our Body Content--> <div id="links"> <h1>Welcome to GeeksforGeeks</h1> <a href= "https://www.geeksforgeeks.org/data-structures"> Data structures </a> <a href= "https://www.geeksforgeeks.org/fundamentals-of-algorithms"> Algorithms </a> </div> <!-- Using script inline to apply CSS--> <script> // Changing text color to green // and aligning to center $("div").css("color", "green"); $("div").css("text-align", "center"); </script> </body> </html> Output:Example 2: Using hover effect on elementWe will use the hover function of jQuery which takes two functions. The syntax isĀ $(element).hover( function(){ // CSS during hover }, function(){ // CSS when not hovering },);Here is the example code. HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> <!-- Include jQuery file using CDN link--> <script src= "https://code.jquery.com/jquery-3.6.0.min.js"> </script> </head> <body> <!-- Our Body Content--> <div id="links"> <h1>Welcome to GeeksforGeeks</h1> <a href= "https://www.geeksforgeeks.org/data-structures"> Data structures </a> <a href= "https://www.geeksforgeeks.org/fundamentals-of-algorithms"> Algorithms </a> </div> <!-- Using script inline to apply CSS--> <script> // Changing text color to green // and aligning to center $("div").css("color", "green"); $("div").css("text-align", "center"); // Using hover function $("h1").hover( // First function is for during hover function () { $(this).css("font-size", 32); }, // Second function is for before // or after hover function () { $(this).css("font-size", 24); $(this).css("transition-duration", "1s"); } ); </script> </body> </html> Output Comment More infoAdvertise with us Next Article How to apply CSS in a particular div element using jQuery ? M manavsarkar07 Follow Improve Article Tags : Web Technologies JQuery jQuery-Methods jQuery-Questions Similar Reads How to apply css property to a child element using JQuery? The task is to apply CSS property to a child element using jQuery. To do that, first we select the child element with the help of children() method in jQuery and then apply CSS property to it with the help of css() method in jQuery. Syntax: // Note : children method selects the direct child to paren 2 min read How to apply styles on an element using jQuery ? In this article, we will learn how one can apply a style on an element using jQuery. Suppose you are building a website or game where you need the user interface to be interactive. In such cases styles can play a huge role there in this post we are going to learn how can we change styles when certai 3 min read How to add CSS properties to an element dynamically using jQuery ? 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 the style property of the selected element. The css() method can be used in different ways. This method can also be used to 1 min read How to apply CSS in even childs of parent node using jQuery ? In this article, we will see how to set styles in even the child of the parent element using jQuery. To set the style on the even child of the parent, we use jQuery :nth-child(even) selector. The :nth-child(even) selector is used to select every element that is the even child of its parent element. 1 min read How to apply CSS style using jQuery ? In this article, we will explore how we can apply CSS styles to HTML elements. It is recommended that you have some basic knowledge of HTML, CSS, JavaScript, and jQuery before beginning this article. It is possible to change the CSS property of an element by using a simple JavaScript API, but we try 2 min read Like