Home > Web Front-end > JS Tutorial > body text

How to get the class name using jquery

coldplay.xixi
Release: 2020-11-19 16:55:00
Original
6396 people have browsed it

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

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.

How to get the class name using jquery

2. In the test.html file, use the div tag to create a line of text for testing.

How to get the class name using jquery

3. In the test.html file, add a class attribute to the div tag with the attribute value cheshi.

How to get the class name using jquery

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.

How to get the class name using jquery

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.

How to get the class name using jquery

#6. Open the test.html file in the browser and click the button to view the results.

How to get the class name using jquery

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!