I think you're looking for the :has selector
$('ul.first:has(ul.second) h2 a').attr("href", "#");
Or, closer to what you're doing:
var second = $(".second");
if(second.length && second.closest(".first")) {
second.closest(".first").find("h2 a").attr("href", "#");
};
Kyle Butt
2010-03-02 14:41:32