Everything that I've seen says you have to check the length of the element you are looking for.
So I think you want
<pre>
if($(this).parents('ul').length==0){
$(this).addClass("active");
}
</pre>
If a parent UL was found, the length would be > 0

