How to find the class of clicked element using jQuery ? Last Updated : 18 Jan, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will find the class of the clicked element using jQuery. To find the class of clicked element, we use this.className property. The className property is used to set or return the value of an element’s class attribute. Using this property, the user can change the class of an element to the desired class. Approach: Here, we use this.className property to get the class name of the current div element. Here, we have added five div elements with different class name and then use jQuery this.className property to get the clicked div elements class name and display it on the console. Syntax: $("div").click(function () { var getClass = this.className; console.log(getClass); }); Example: HTML <!DOCTYPE html> <html lang="en"> <head> <title> How to find the class of the clicked element using jquery? </title> <!-- Import jQuery cdn library --> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <script> $(document).ready(function () { $("div").click(function () { var getClass = this.className; console.log(getClass); }); }); </script> </head> <body style="text-align: center;"> <h1 style="color: green;"> GeeksforGeeks </h1> <h3> How to find the class of the clicked element using jquery? </h3> <div class="main">Main Div</div> <div class="GFG">GFG</div> <div class="Geeks">Geeks</div> <div class="G4G">GeeksforGeeks</div> <div class="welcome">Welcome</div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to get styles of a clicked division using jQuery ? V vkash8574 Follow Improve Article Tags : Web Technologies JQuery jQuery-Questions Similar Reads How to filter the children of any element using jQuery ? In this article we will learn how to filter the children of any element in JQuery. JQuery is a fast and lightweight JavaScript library that simplifies the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM), and JavaScript. It is widely famous for its motto o 3 min read How to find an element by text using jQuery ? We will learn how to find an element using jQuery's API. This article requires some knowledge of HTML, CSS, JavaScript, Bootstrap, and jQuery. The elements can be selected based on whether they contain the string we want to find. This can be done using the jQuery contains selector to select elements 2 min read How to display the tag name of the clicked element using jQuery ? Given a HTML document containing some elements and the task is to display the clicked element. Approach: First we create a HTML document containing some elements and add a jQuery function to display the clicked element. We select the HTML body using jQuery selector and when user click the element th 1 min read How to get styles of a clicked division using jQuery ? In this article, we will learn how to get the styles (width, height, text color, and background color) of a clicked division using jQuery. Approach: The css() method is used to get the CSS property values of the selected element in jQuery. We use the css() method in jQuery that takes an array of nam 2 min read How to find which DOM element has the focus using jQuery? The HTML DOM has an activeElement Property. It can be used to get the currently focused element in the document: Syntax: let ele = document.activeElement; Return value: It returns the currently focused element in the document. Example Code Snippets: Example 1: let eleName = document.activeElement.ta 1 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 Like