I'm running some tests to understand what is the difference between simple use of a selector eq()
and find()
, so that you can select the first row of a table for example.
Example 1:
$('table tbody tr:first') // ok
$('table tbody tr').find(':first'); // errado - pega todos os elementos da tr
$('table tbody').find('tr:first'); // ok
In these 3 tests I realized that for find()
to work it is necessary to be accompanied by a tag, if I want to create a variable and store this selector, how can I access the objects of this element by the find()
selector?
Example 2:
var $tab = $('table tbody tr');
$tab.find(':first'); // errado, fica no mesmo jeito do exemplo acima.
Detail, I discovered that it can be accessed by eq()
:
Example 3:
$tab.eq('0'); // ok
Example 3 solves my problem, but is there any way to make it work using Example 2?
What are the differences of the selector eq()
and find()
, besides knowing that eq()
must be informed the exact index where the information is and find()
searches for a corresponding item?
By the logic of how they work it seems that eq()
has higher performance, not that it is significant in the process, but is there a lot of difference?