Been struggling with this simple selector problem a couple of hours now and must be missing something obvious. I have a <ul> in which some <li>s have nested <ul>s. Each <li> contains a link and when this is clicked I want to execute a function (rather than navigate), but importantly, this should only happen for the links contained in the parent <ul> and not any links that may be present in a nested <ul>. Simple you'd think:
HTML:
<ul>
<li>
<a href="dontleavethis.page">A link</a>
<ul>
<li><a href="navigate.there">A nested link</a></li>
<li><a href="navigate.somewhere">Another nested link</a></li>
</ul>
</li>
</ul>
jQuery:
$('li:has(ul) a').click(function() {
bla bla bla...
return false;
});
Thing is, no matter how I phrase my selector, I cannot stop the links in the nested <ul> from triggering the click handler. They clearly do not match the ":has(ul)" criteria of the selector but the handler still gets attached for some reason. What am I doing wrong here?
Many thanks in advance,
JS