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()].
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.
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.
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.
<script></script> tag. The js logic code of the page will be written in within this tag.
id(mytest), and use the bind() method to bind the click event to it , the code is as follows:
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.
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!