I am learning jQuery, and I was wondering what is the difference between these two selectors:
$('#puzzleGrid table tr td img');
and
$('#puzzleGrid').children('table').children('tr').children('td').children('img');
Thank you!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This children() selector – as pointed out by Fraicio Matte –
This first one will use the DOM QSA when available, which is a quadrillion times faster than the second example full of function calls’ overhead.
is very specific to getting children elements of the previous element
and this – descendant selector
Will find any “table” descendants(any table element under) of element with id=puzzleGrid.. and any descendant tr of the found tables.. and so on.
The equivalent to the first one would be using
>child-selector