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
$('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.
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"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.