4
I am conducting some tests to understand what is the difference of the simple use of a selector eq()
and find()
, to be able to 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 those 3 tests I realized that for the find()
work it is necessary to be accompanied with a tag, if I want to create a variable and store this selector, as I will be able to access the objects of this element by the selector find()
?
Example 2:
var $tab = $('table tbody tr');
$tab.find(':first'); // errado, fica no mesmo jeito do exemplo acima.
Detail, I found that can be accessed by eq()
:
Example 3:
$tab.eq('0'); // ok
Example 3 solves my problem, but there is some way to make it work using example 2?
What are the differences of the selector eq()
and find()
, besides knowing that eq()
the exact index where the information is find()
search for a matching item?
From the logic of how they work it seems that eq()
has higher performance, not that it is something significant in the face of the process, but there is a lot of difference ?
Why did I get -1 ?
– Gabriel Rodrigues