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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:00:47+00:00 2026-05-24T08:00:47+00:00

I am having an issue with applying css styles to dropdown navigation menus within

  • 0

I am having an issue with applying css styles to dropdown navigation menus within WordPress using jQuery.

Basically, I have 5 navigation links. The intention is to have each of the dropdown links to have its own colour. The code I have used seems to work when, say for example, every link has a dropdown in place. However, if I have a dropdown only on the second link and also on the fourth link, then the fourth link dropdown colour uses the colour from the what the third dropdown colour would be ie nth-child(4) should use #37595c but instead uses the colour of nth-child(3). Any help with resolving this issue would be greatly appreciated. Code below:

$(document).ready(function(){
    $("#nav_main ul li:nth-child(1) ul.sub-menu a").css("background", "#9c1b36");
    $("#nav_main ul li:nth-child(2) ul.sub-menu a").css("background", "#808021");
    $("#nav_main ul li:nth-child(3) ul.sub-menu a").css("background", "#4a3349");
    $("#nav_main ul li:nth-child(4) ul.sub-menu a").css("background", "#37595c");
    $("#nav_main ul li:nth-child(5) ul.sub-menu a").css("background", "#41403e");  
});

Have replicated the issue in jsfiddle. If you hover over ‘Nav Two’ and then ‘Nav Four’ you will see that ‘Nav Four’ is using the colour of what would be used if ‘Nav Three’ was in effect: http://jsfiddle.net/cknz/vmRBp/3/

  • 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-24T08:00:48+00:00Added an answer on May 24, 2026 at 8:00 am

    Use the > selector to make sure the ULs are children of #nav_main and the LIs are children of the ULs. And use nth-of-type instead of nth-child:

        $("#nav_main > ul > li:nth-of-type(1) a").css("background", "#9c1b36");
        $("#nav_main > ul > li:nth-of-type(2) a").css("background", "#808021");
        $("#nav_main > ul > li:nth-of-type(3) a").css("background", "#4a3349");
        $("#nav_main > ul > li:nth-of-type(4) a").css("background", "#37595c");
        $("#nav_main > ul > li:nth-of-type(5) a").css("background", "#41403e");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an issue applying css dynamically to a loaded div using the
I'm having an issue applying a CSS Width with a percentage and a decimal
Having issue with my navigation. How can I prevent it? My CSS file looks
Having an issue here that I have tried everything I can think of but
Experts, I'm having issue when sending emails out. Currently, I have a feedback form
We are using MSDTC for SQL transactions. I am having issue with setting up
Having an issue applying the rules that rounders the upper-left and upper-right corners in
We have a device that support SAE J1939 interface and having issue with finding
I'm having an issue with the memory management in my application. I have an
Having a strange rendering issue with Safari: I have a table inside a div.

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.