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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:14:32+00:00 2026-06-13T11:14:32+00:00

I am trying to select top level siblings using jquery. I can’t use class

  • 0

I am trying to select top level siblings using jquery. I can’t use class names which has made the task more difficult.

<ul>  
<li>  
    <a href="index.html">1</a>
    <ul>
        <li>  
            <a href="indexsub.html">sub1</a>  
        </li>
        <li>  
            <a href="indexsub2.html">sub2</a>  
        </li>
    </ul>  
</li>  
<li>  
<a href="index2.html">2</a>  
</li>
<li>  
<a href="index3.html">3</a>
</li>
</ul>​   

Following is the link to JSfiddle.

http://jsfiddle.net/KMhzy/28/

I want to change href=”#” for all tags except child list elements (i.e sub1 and sub2).

  • 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-13T11:14:33+00:00Added an answer on June 13, 2026 at 11:14 am

    First, you have to change your HTML (you are missing ul inside nested menu):

    <ul>
        <li>
            <a href="index.html">1</a>
            <ul>
                <li>
                    <a href="indexsub.html">sub1</a>
                </li>   
            </ul>
        </li>
        <li>
            <a href="index2.html">2</a>
        </li>
        <li>
            <a href="index3.html">3</a>
        </li>
    </ul>​
    

    Next, you can achieve what you want with this:

    $("ul li a").not("ul li li a").attr("href", "#");
    

    (other solutions proposed here are hard coded to some ‘sub1’ value, this should do the trick for all submenus if that is what you want).

    Here is a jsfiddle

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

Sidebar

Related Questions

I'm trying to use the statement SELECT TOP 1 * FROM tasks WHERE dueDate
I'm trying to convert this SQL query to L2S.. SELECT TOP 5 vt.* FROM
I trying to select all li elements at second level of the list add
In trying to select elements that have any attributes, the following throws a jQuery
I am trying to select the last record from a table in MySQL using
I'm trying to beat a basic accordion style menu into submission – using jQuery.
I am trying to do the following: EXECUTE sp_executesql N'SELECT TOP 10 * FROM
I'm currently trying to create a class which implements IEnumerable<T> in order to construct
I'm trying an update with a conditional sub-select which could return null... UPDATE aTable
I'm trying to create a leaderboards page which shows the top 10 users depending

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.