I have the follow html:
<div id="x">
<div id="x1">
</div>
....
</div>
....
<div id="x2">
<table id="y">
</table>
</div>
开发者_开发问答From "x" I need to reach "y", something like $("#x").find("#y")
Suppose that I do not know what has in the "...".
How to do this?
You can go up one level with parent()
and use find()
from there.
$('#x').parent().find('#y');
Try the following
$('#x').siblings().find('#y')
In truth though this makes little sense to do given that both elements in this case have id
values. It's much faster to just search for #y
directly. If you do actually have multiple id
s with the same value that's a problem and you should move to an id generation scheme or classes
I think what you are looking for is...
$('#y', $('#x'))
The second parameter is the scope of the selector.
精彩评论