Check if html element has a specific class

We can check if some html element has a specific class using jquery hasClass method. It returns Boolean value.

<input type="button" value="Check class" onclick="CheckClass()" />
<div id="myDiv" class="myClass">
    This is a div
</div>


<script type="text/javascript">
    function CheckClass() {
       if ($("#myDiv").hasClass("myClass"))
            console.log("Div has class myClass");
 }

</script>

Comments

Popular posts from this blog

Using Progress Bar In C#

Get elements by class name in javascript

Jquery serer side datatables in asp.net