Home  >  Article  >  Web Front-end  >  Detailed analysis of the difference between children and find in Jquery_jquery

Detailed analysis of the difference between children and find in Jquery_jquery

WBOY
WBOYOriginal
2016-05-16 17:11:43817browse

First look at a piece of HTML code, as follows:

Copy the code The code is as follows:

< ;table id="tb">
                                                                              🎜>                                                                              td>
           
                                                              td>4
                                                            /td>
                                                                                                                                                                                                  



If I want to get the value of the second td in the second tr:


Children:


Copy code


Find :


Copy code
As a result, the value obtained through children is: null, and through The value obtained by find is: 4. Why is this?

After checking the information, what is obtained through children is the subordinate elements of the element, and what is obtained through find is all the subordinate elements of the element.
Now back to the above, we can conclude that $("#tb>tbody").children() obtains two tr elements (excluding their child elements td),
The selector in children is to filter the two obtained tr elements according to the conditions, so the above writing method cannot get the value.

If we must use children, we can write it like this:

Copy the code

Statement:
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