Home > Article > Web Front-end > How to get the class name using jquery
How to use jquery to get the class name: First use the div tag to create a line of text, add a class attribute to the div tag; then in the js tag, get the div object through the class name, use the [attr()] method Get the class name.
How to get the class name using jquery:
1. Create a new html file and name it test.html , used to explain how jQuery obtains class names.
2. In the test.html file, use the div tag to create a line of text for testing.
3. In the test.html file, add a class attribute to the div tag with the attribute value cheshi.
4. In the test.html file, create a button button, bind the onclick click event to the button, and when the button is clicked, execute the getclass() function.
5. In the js tag, create the getclass() function. Within the function, obtain the div object through the class name, and use the attr() method to obtain the class name.
#6. Open the test.html file in the browser and click the button to view the results.
Related free learning recommendations: JavaScript (video)
The above is the detailed content of How to get the class name using jquery. For more information, please follow other related articles on the PHP Chinese website!