JQuery check if class exist

JQuery check if class exist

You want to perform some action based on if is there exist a class for given element. .hasClass gives Boolean value true if class exist on that element.

JQuery hasClass example

    <title>Jquery Get TextBox Value</title>
<script src=http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script type="text/javascript" language="javascript">

$(document).ready( function (){ 

    $("#Button1").click( function(){      



         <input class="DefaultTextClass" id="txtName" type="text" />
           <input id="Button1" type="button" value="Click To Get Value" />                     

In above example $("input:text") gives all input element whose type is text. and .hasClass JQuery method

is used to check if given class exist on that element or not.



JQuery check if class existJQuery add/remove Class DynamicallyLearning JqueryBasics of jqueryHow To Hide Div On Click Using JQueryJQuery Get Element By ID or class name or tag nameJQuery Radio Button CheckedjQuery Select element by class nameJquery Radio Button Checkedasp.net Gridview checkboxHow to check image is loaded using JQuery


My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.

I'm Satalaj.