How to use HTML HasClass Method in JQuery

This article describe about HTML HasClass Method in JQuery.
  • 1965

HTML hasclass() method in jQuery

The hasclass() method is used to check any element have a specified class.

If class will provide the specified element, then this method will return "true" message in the message box.

Syntax

$(selector).hasClass(class)

Example

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function ()

 {

        $("button").click(function ()

{

            alert($("p").hasClass("base"));

        });

    });

</script>

<style type="text/css">

.base

{

font-size:100%;

color:blue;

}

</style>

</head>

<body>

<h1>This is a JQuery</h1>

<p class="base">This is a .Netheaven.</p>

<p>This is HTML.</p>

<button>Click this button</button>

</body>

</html>

Output1

op1.jpg

Output2

op2.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.