user1032531 user1032531 - 4 months ago 10
jQuery Question

Finding closest jQuery sibling of given type

#getIt
will always be a sibling of
#clicked
, however,
#getIt
doesn't really have an
id
attribute, and one is just included for this posts benefit.

Starting at
#clicked
, what is the cleanest way to select
#getIt
? I am sure I could do so using two
next()
or
parent()
and
children()
, however, thought maybe a single method is available.

<div>
<table><table>
<button id="clicked">click</button >
<p>bla</p>
<table id="getIt" class="myTable" data-id="123"></table>
<p>bla</p>
</div>

Answer

you can use siblings :

$('#cliked').siblings('#getIt')