Home > Article > Web Front-end > How to get the value of class with jQuery
In jQuery, you can use the attr() method to get the class value of an element, the syntax format is "$(selector).attr('class')". The attr() method can return the attributes and values of the selected element, and the class itself is an attribute of the element, so it can be obtained using the attr method.
The operating environment of this tutorial: windows7 system, jquery1.10.0 version. This method is suitable for all brands of computers.
Recommended tutorial: jquery video tutorial
jQuery gets the value of the class
jQuery gets the value of the HTML attribute. An operation to do, since the class itself is also an attribute of the element, the value of the class can be obtained through the attr method.
The code is as follows:
$('#demo').attr('class');
attr() method can return the attributes and values of the selected element, and return the value of the first matching element.
Syntax: $(selector).attr(attribute)
Complement: javascript method
You can also use the element object of javascript to obtain it. The code is as follows:
$('#demo')[0].className;
For more programming-related knowledge, please visit: Programming Teaching! !
The above is the detailed content of How to get the value of class with jQuery. For more information, please follow other related articles on the PHP Chinese website!