I am trying to find out what div is the span is in using jquery.
here is a eg.
<div id='one'></div>
<div id='two'></div>
<div id='three'><span id="find_me"></span></div>
thanks
Use .closest()
to find the closest ancestor div
(.parent()
will only find it it if the div is the immediate parent).
$('#find_me').closest('div').attr('id')
alert ( $("#find_me").parent().attr("id") ); // <- three
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With