Open In App
Related Articles

jQuery hasClass() Method

Improve Article
Save Article
Like Article

The hasClass() is an inbuilt method in jQuery which check whether the elements with the specified class name exist or not.



Parameter: It accepts a “className” parameter which specifies the class name needed to search in the selected element.

Return Value: It returns true if the search is successful otherwise false.

jQuery code to show the working of this method:


<!DOCTYPE html>
    <script src=
        $(document).ready(function () {
            $("button").click(function () {
        .find {
            font-size: 120%;
            color: green;
        body {
            width: 80%;
            height: 200px;
            padding: 20px;
            display: flex;
            justify-content: center;
        div {
            width: 600px;
            height: 200px;
            border: 2px solid green;
        <h1>Heading 1</h1>
        <p class="find">
            Geeks for Geeks !.
            This is normal paragraph.
        <button>Click me!</button>



Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 10 Jul, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials