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

How to use this to select child elements in jquery

coldplay.xixi
Release: 2023-01-04 09:36:34
Original
4072 people have browsed it

How jquery uses this to select child elements: first use the span tag to create multi-line text; then use the [bind()] method to bind the click event to the p tag; then obtain it through [$(this)] The currently clicked object; finally obtain all the child elements in it through [html()].

How to use this to select child elements in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer. This method is suitable for all brands of computers.

Recommended: jquery video tutorial

Jquery uses this method to select child elements:

1. Create a new html file , named test.html, is used to explain how jquery uses $(this) to select other sub-elements below.

How to use this to select child elements in jquery

2. In the test.html file, introduce the jquery.min.js library file and successfully load the file before you can use the methods in jquery.

How to use this to select child elements in jquery

3. In the test.html file, within the p tag, use the span tag to create multi-line text, and the span tag is used as a child of the p tag. element, and set the id of the p tag to mytest.

How to use this to select child elements in jquery

##4. In the test.html file, write the

tag. The js logic code of the page will be written in within this tag.

How to use this to select child elements in jquery

5. In the js tag, obtain the p tag object through

id(mytest), and use the bind() method to bind the click event to it , the code is as follows:

How to use this to select child elements in jquery

6. In the

bind() method, obtain the currently clicked object through $(this) and obtain it through html() All the child elements in it are saved in html variables. Finally, the alert() method is used to output the child elements.

How to use this to select child elements in jquery

7. Open the test.html file in the browser, click on the text to see the effect.

How to use this to select child elements in jquery

Related free learning recommendations: javascript(Video)

The above is the detailed content of How to use this to select child elements in 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 [email protected]
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!