I donโt think that you can only do this with a selector, unless it happens that the elements a are not only the first anchor, but also the first child of any type inside the โpanelsโ of the div (in this case, you can use :first-child )
You may have to put some logic in the handler to verify that clicking the anchor is the first anchor in the div . Something like that:
$("#panel").delegate(".panels a", "click", function() { if ($(this).siblings("a").andSelf()[0] === this) {
Living example
This works because siblings and andSelf ensure that the array inside the jQuery object is kept in the order of the document, so check if this element works [0] th.
source share