The problem is that .has()
returns a jQuery collection, not a boolean value (see the docs at http://api.jquery.com/has/). You can check that the collection contains an element with:
if (jQuery(this).parent().has("ul")[0]) {
Alternatively, if you're going to preventDefault
on the a
tags, why not just remove the href attribute for the ones with children? You can then remove the preventDefault
altogether.