JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/ui-lightness/jquery-ui.css">
<div>
<!-- even though it is nested,
this <a> will be first
when searching for tagName-->
<div>
<a><span>sorry!</span></a>
</div>
<div>
<a><span>sorry!</span></a>
</div>
<a><span>sorry!</span></a>
<a><span>sorry!</span></a>
<a><span>sorry!</span></a>
<a><span style="color:blue;">CLICK THIS ONE</span></a>
<a><span>sorry!</span></a>
<a><span>sorry!</span></a>
<a><span>sorry!</span></a>
</div>
JavaScript
function q(elem) {
var tag = elem.tagName;
var idx = 0;
$.each($(elem).parent().children(tag), function(i) {
if (this === elem) {
idx = i;
return false;
}
});
idx++;
return $(tag + ':eq(' + idx + ') > span', $(elem).parent());
}
$('a').click(function() {
var result = q(this);
alert(result.html());
});