The differences between children and find in Jquery are explained in detail

  • 2020-03-30 00:01:22
  • OfStack

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

<table id="tb">

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


$("#tb>tbody").children("tr:eq(1) td:eq(1)").html()

Find      :

$("#tb>tbody").find("tr:eq(1) td:eq(1)").html()

  As a result, the value obtained by children is: null, while the value obtained by find is: 4. Why?

  Looking up the data, children is the child element of the element, and find is all the child elements of the element.

  So back up here, we have $("#tb> Tbody ").children() gets two tr elements (not including their child td),

  The selector in children filters by condition in the two tr elements obtained, so the above method does not get the value.

  If we must use children, we can write:


Related articles: