If you are using an ID, nesting is usually irrelevant. Specifying the
nesting won't help you find it. It will only help you to
qualify/disqualify it.
As IDs must be unique within a document, this is all you need to
find the element with the ID:
$('#test')
To find the
<tr>
:
$('#test').closest('tr');
The only reason to
ever put any qualifier in front of or adjacent to an ID selector
would be if you only want to find it should it be found within
some nesting or when accompanied by some class or other
qualification of the same element.
I often see
selectors like
$('.xyz div.#my-id')
and 99% of the time
the extra stuff is unneeded rubbish.
Here's a couple
of legitimate reasons for combining an ID with something else:
$('#my-id.selected')
I want to find the
element with id='my-id'
, but only if it also has
the class ' selected '.
$('.selected #my-id')
I want to find the
element with id='my-id'
, but only if some parent
has the class ' selected '. Think inside of table
rows, list items, etc. However, this one is much more likely
encountered in CSS than in JS code.
If you duplicate the
ID within the document, you've broken the rules, and all
bets are off.
What are you really
trying to accomplish?