test

Choosing a descendant in jQuery, if I have an element reference, already

I have the following HTML:

<table id="myTable">
  <tr>
    <td><div>test</div></td>
  </tr>
  <tr>
    <td><div>test</div></td>
  </tr>
</table>

I have a link to #myTablein a variable $myTable.

How can I select all tags divwithout using the string #myTableagain (i.e. use only the object $myTable)?

To clarify, assuming this example worked:

$('#myTable div')

... it does not meet my criteria since I do not want to re-specify #myTable.

In addition, I would prefer not to list each parent in the hierarchy as follows:

$myTable.children('tr').children('td').children('div')

I tried to use

$myTable.children('div')

... but it seems that only immediate children who are not elements are chosen div.

I want to use something short:

$myTable.descendants('div')
+3
3

find jQuery.

$myTable.find('div');

:

$('div', $myTable);

+5

find , .

$myTable.find('div');

+4

, "#" id. :

<table id="myTable">

$('div', $myTable), div.

+1

Source: https://habr.com/ru/post/1778634/


All Articles