How to check an element has certain CSS style using jQuery ? Last Updated : 16 Oct, 2019 Comments Improve Suggest changes Like Article Like Report Given an HTML document containing some CSS property and the task is to check whether an element has a specific CSS style or not with the help of jQuery. Approach 1: Use css() method to check an element contains certain CSS styles or not. Example: This example uses css() method to check an element contains certain CSS style or not. html <!DOCTYPE HTML> <html> <head> <title> How to check an element has certain CSS style using jQuery ? </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> </head> <body style = "text-align:center;"> <h1 style="color:green"> GeeksForGeeks </h1> <p id = "GFG_UP" style = "font-size: 15px; font-weight: bold;"> </p> <button onclick = "GFG_Fun()"> click here </button> <p id = "GFG_DOWN" style = "color:green; font-size: 20px; font-weight: bold;"> </p> <script> var up = document.getElementById('GFG_UP'); var down = document.getElementById('GFG_DOWN'); var n = 1/0; up.innerHTML = "Click on the button to check" + " if H1 has style, color = green."; function GFG_Fun() { if ($("#h1").css("color") == "rgb(0, 128, 0)") { down.innerHTML = "H1 has CSS style, color: green"; } else { down.innerHTML = "H1 has not CSS style, color: green"; } } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: Approach 2: Use hasClass() method to check an element contains certain CSS styles or not. Example: This example uses hasClass() method to check an element contains certain CSS style or not. html <!DOCTYPE HTML> <html> <head> <title> How to check an element has certain CSS style using jQuery ? </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> </head> <body style = "text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id = "GFG_UP" style = "font-size: 15px; font-weight: bold;"> </p> <button onclick = "GFG_Fun()"> click here </button> <p id = "GFG_DOWN" class = "color" style = "font-size: 20px; font-weight: bold;"> </p> <script> var up = document.getElementById('GFG_UP'); var down = document.getElementById('GFG_DOWN'); var n = 1/0; up.innerHTML = "Click on the button to check if" + " P[id = GFG_DOWN] has style, color =" + " green using class."; function GFG_Fun() { if ($("#GFG_DOWN").hasClass('color')) { down.innerHTML = "P[id = GFG_DOWN] has CSS style, color: green"; } else { down.innerHTML = "P[id = GFG_DOWN] has not CSS style, color: green"; } } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: Comment More infoAdvertise with us Next Article How to check an element has certain CSS style using jQuery ? P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies CSS-Misc jQuery-Misc Similar Reads How to check an element contains a class using jQuery? Method 1: Using hasClass() method: The hasClass() is an inbuilt method in jQuery which check whether the elements with the specified class name exists or not. It returns a boolean value specifying whether the class exists in the element or not. This can be used to check for multiple classes. Syntax: 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 and remove CSS classes to an element using jQuery ? In this article, we will see how to add or remove the CSS classes to an element using jQuery. To add the CSS classes to an element we use addClass() method, and to remove the CSS classes we use removeClass() method. Syntax: The syntax for adding CSS classes to an element: $('selector').addClass(clas 2 min read 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 change style of elements on scroll using jQuery ? We have given an HTML document containing some CSS properties, and the task is to change the CSS property to a particular element after scrolling the page using jQuery. To change the style of element on scroll, we get the number of pixels by which the content of an element has been scrolled horizont 2 min read Like