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 407835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:38:01+00:00 2026-05-12T17:38:01+00:00

<ul> <li><a href=#>LEVEL 1</a> <ul> <li>…</li> </ul> </li> <li><a href=#>LEVEL 1</a> <ul> <li>…</li> </ul>

  • 0
<ul>
   <li><a href="#">LEVEL 1</a>
      <ul>
         <li>...</li>
      </ul>
   </li>
   <li><a href="#">LEVEL 1</a>
      <ul>
         <li>...</li>
      </ul>
   </li>
</ul>

I have a nested list and I want to use jQuery to add class to the LI that containts A>LEVEL 1 based on this condition: if a nested UL exists AFTER UL LI A, do x else y.

Thanks.

  • 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-05-12T17:38:01+00:00Added an answer on May 12, 2026 at 5:38 pm

    To simply add a class to the <li> elements that have an anchor followed by a <ul> do this:

    $("ul li:has(a + ul)").addClass("someClass");
    

    If you really need different classes on whether it’s true then you’ll need some code:

    $("ul li").each(function() {
      var a = $(this).children("a");
      if (a.next("ul").length > 0) {
        $(this).addClass("first");
      } else {
        $(this).addClass("second");
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this: <a class=top_level_active href=javascript:Submit('menu_home')>Account Summary</a> I want to click that link but
I have three level of submenu created dynamically. I want to add class=active where
I've got a list that looks like this: <li class = current_parent level-0> <a>
In jQuery you can do : $(a[href$='.img']).each(function(index) { alert($(this).attr('href')); } I want to write
I have a set of nested unordered lists that represents page navigation. The list
I have a href tag that goes like this : href=download.php?file={$sp->attachment_1}&flag=ds&r_id={$userid}&scpl_id={$sp->sp_id}; that works and
I have an href in HTML that I dynamically produce from a server. I
I have this href link with text either attivo or non attivo User can
I have this href defined in my markup: foreach (Car car in Model.Cars) {
How to add href close link to Fancybox modal window? I want close Fancybox

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.