Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9114695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:15:27+00:00 2026-06-17T04:15:27+00:00

I have this selector: $(‘ul:not(.sub-menu) > li, ul.sub-menu > li:last-child’).not(‘:has(ul.sub-menu)’); which gets these elements:

  • 0

I have this selector:

$('ul:not(.sub-menu) > li, ul.sub-menu > li:last-child').not(':has(ul.sub-menu)');

which gets these elements:

  1. Every direct li descendant whose parent is not .sub-menu (unless it’s the last, cf. 2.)
  2. Every last li element of an ul.sub-menu
  3. Exclude all li‘s that are parent to a ul.sub-menu

Now, I want to use this in an if-statement, which is inside a hover-function. In other words, it’s got to be relative to that list item instead of being the list item.

Something like this:

$("nav li").hover(function () {
  var $this = $(this); 
  if (($this.parent("ul:not(.sub-menu)") || ($this.parent("ul.sub-menu") && $this.is(":last-child"))) && $this.not(":has(ul.sub-menu)")) {
     // do something
  }
});

But this does not work. I think it has something to do with combining the OR and AND selectors inside an if-statement, but I can’t seem to debug it: the code above selects all list items without a distinction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:15:28+00:00Added an answer on June 17, 2026 at 4:15 am

    $this.parent("ul:not(.sub-menu)") is never falsy, even if the set is empty.

    Use $this.parent("ul:not(.sub-menu)").length instead in your condition.

    The whole if statement would thus look like this :

    if (
        (
            $this.parent("ul:not(.sub-menu)").length
            || ( $this.parent("ul.sub-menu").length && $this.is(":last-child") )
        ) && !$this.hasClass("sub-menu")
    ) {
         // do something
    }
    

    Details :

    if ($('#a')) { // always verified
    
    if ($('#a').length>0) { // verified if there is an element with id a
    
    if ($('#a').length) { // identical to last one
    

    As written by the MDN :

    Examples of expressions that can be converted to false are those that
    evaluate to null, 0, the empty string (“”), or undefined

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I have this selector: .form .mid td p:last-child:not(:only-child) { margin-bottom: 0; } It's
I have this selector: $(table.details tbody tr:not(.details)) But I'm wondering why this inner table
Example: I have a selector like this, which I give to another method as
I have a jquery selector which looks like this: $(#MasterListDVWP tr td:contains(' + currentSchool
I have no Idea why this selector does not work. The HTML element is
i have this jquery code which poplautes a input selector, which should display like
I have this code: NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:temp/10.0f target:self selector:@selector(verify) userInfo:nil repeats:YES]; CCMoveTo
Does anyone have any idea what this jQuery selector will do? object.find('td:eq(1) div div');
I have code like this - (IBAction)onClick:(id)sender { NSThread *thread = [[NSThread alloc]initWithTarget:parser selector:@selector(adapter:)
For example I have a method that looks like this [self performSelectorOnMainThread:@selector(someMethod) withObject:data waitUntilDone:YES];

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.