I am doing with this plugin :
<table>
<tr>
<td>
<a class="linkType1" href="google.com">
Google
</a>
<span style="display: none;">Goooooooooooogle</span>
</td>
</tr>
<tr>
<td>
<a class="linkType1" href="yahoo.com">
Yahoo
</a>
<span style="display: none;">Yaaaaaaaaaaaaaaho</span>
</td>
</tr>
</table>
How can I select the closest span of linkType1-anchors for displaying as tooltip ?
Currently I am doing :
jQuery(document).ready( function() {
jQuery("a.linkType1").tooltip({
bodyHandler: function() {
alert(jQuery(this).closest("span").html()); // this alert is showing `null`
return "hi"; // i need to setup the alerted content here
},
showURL: false
});
});
Your
spanelements aren’t ancestors of the links, soclosest(which looks for a match for the selector on the current element or its ancestors) isn’t what you’re looking for.Based on your markup, you might want
next("span")(which will find the next sibling, but only if it’s a span; it doesn’t continue with subsequent siblings) or possiblynextAll("span").first()(which will find the first next sibling that’s a span, in case you ever put something between theaand thespan), which finds all subsequent siblings withnextAlland then grabs the first of them (the one nearest the link) viafirst. Soor