Get Class Name Using jQuery

For More Videos Visit Our YouTube Channel




Here we consider how to get the class name using jQuery. Lets start with one example here. Suppose we have a div with class clsDiv as shown here.

Get Class Name Using jQuery of Any Form Element, Get Class Name Using jQuery, Get Class Name of element Using jQuery, Get Class Name of form element Using jQuery, Class Name of form element, Class Name of form element Using jQuery, jQuery get class name, class name using jquery, hasclass, prop, attr, PHP, HTML

The Div id is divID. Now for getting the class name of this Div, we can use following code.

$(function () {
         var ClassName = $('#divID').attr('class');
});




$(function () {
         var ClassName = $('#divID').prop('class');
});




In jQuery, we first find the Div by using its ID. And then retrieve its attribute named class using jQuery attr or prop. That's all, by this way we can get the class name of form element using jQuery.