Home > Article > Web Front-end > How to use $(this) in jquery to select the child elements below it
The method for jquery to use $(this) to select the sub-elements below it: first use the span tag within the p tag to create multi-line text; then use the bind method to bind the click event to the p tag through [$ (this)] obtains the currently clicked object; finally obtains all child elements through [html()].
The operating environment of this tutorial: windows10 system, jquery2.2.4, this article is applicable to all brands of computers.
Recommended: "jquery video tutorial"
Jquery uses $(this) to select the child elements below it:
1. Create a new html file, named test.html, 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. The span tag is used as a sub-element of the p tag, and the p tag is set at the same time. The id is mytest.
##4. In the test.html file, write the<script></script> tag. The js logic code of the page will be written in within this tag.
bind() method to bind the click event to it , the code is as follows:
$(this), and through
html ()Get all the child elements in it and save it in the html variable. Finally, use the
alert() method to output the child elements.
Related free learning recommendations:JavaScript (video)
The above is the detailed content of How to use $(this) in jquery to select the child elements below it. For more information, please follow other related articles on the PHP Chinese website!