0

I need to find the class name specified in the input attribute using jquery

<Html>
<body>
<input type="text" class="name"/>
</body>
</Html>

here how i can find the class name using jquery

Roy thomas
  • 115
  • 1
  • 8
  • 1
    use `hasClass()` https://api.jquery.com/hasclass/ `Description: Determine whether any of the matched elements are assigned the given class.` – guradio Apr 13 '16 at 11:35
  • Your title and your question's body conflicts with the exact requirement – Rajaprabhu Aravindasamy Apr 13 '16 at 11:37
  • i want to get the class name ,i dont know what is the class name present for the element then how to find it? – Roy thomas Apr 13 '16 at 11:39
  • Possible duplicate http://stackoverflow.com/questions/2400386/get-class-name-using-jquery – John R Apr 13 '16 at 11:42
  • Possible duplicate of [jQuery - Find any input with a given class that has no value](http://stackoverflow.com/questions/3477311/jquery-find-any-input-with-a-given-class-that-has-no-value) – Søren Debois Apr 13 '16 at 11:48
  • Possible duplicate of [Get class list for element with jQuery](http://stackoverflow.com/questions/1227286/get-class-list-for-element-with-jquery) – Henders Apr 13 '16 at 12:15

3 Answers3

0

Try .attr() :-

$("input[type='text']").attr('class');

DEMO

Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69
0

$('input').hasClass('name') ? alert('has class name') : alert('has no class name') 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="name"/>

use .hasClass

Description: Determine whether any of the matched elements are assigned the given class.

guradio
  • 15,524
  • 4
  • 36
  • 57
0

Try this:

var className = $('.name').attr('class');
alert(className);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="name"/>
E.Agolli
  • 552
  • 2
  • 11