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

  • Home
  • SEARCH
  • 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 6817801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:05:59+00:00 2026-05-26T21:05:59+00:00

I’m trying to get my theme to add CSS class names to the ‘ul’

  • 0

I’m trying to get my theme to add CSS class names to the ‘ul’ elements in the main-menu in Drupal 7.

HTML mock-up code:

<ul class="topnav">
    <li><a href="#">Home</a></li>
    <li>
        <a href="#">Tutorials</a>
        <ul class="subnav">
            <li><a href="#">Sub Nav Link</a></li>
            <li><a href="#">Sub Nav Link</a></li>
        </ul>
    </li>
    <li>
        <a href="#">Resources</a>
        <ul class="subnav">
            <li><a href="#">Sub Nav Link</a></li>
            <li><a href="#">Sub Nav Link</a></li>
        </ul>

</ul>

As you can see, the “first level” ul has a class name of “topnav”, the following nested ul has a class name of “subnav”. I’m hooking up a jQuery drop down menu and want to apply it without the use of modules. Yes, I’ve tried the “Menu Attributes” module but that doesn’t work here.

I’ve been searching all day and cannot seem to find a complete solution. I know about superfish / and other themes that come with sf, but I’m wanting my own solution.

Edit:
Ok, I’ve gotten further. I have a menu with subs on which jquery is initially hiding the subs, however, I can’t get jquery to show the subs on a given event: hover over “ul.menu li span”

Here’s my CSS:

ul.menu {
    list-style: none;
    padding: 0 20px;
    margin: 0;
    float: left;
    width: 920px;
    background: #222;
    font-size: 1.2em;
    background: url(topnav_bg.gif) repeat-x;
}


ul.menu li {
    float: left;
    margin: 0;
    padding: 0 15px 0 0;
    position: relative; /*--Declare X and Y axis base for sub navigation--*/
}



ul.menu li a{
    padding: 10px 5px;
    color: #000;
    display: block;
    text-decoration: none;
    float: left;
}



ul.menu li a:hover{
    background: url(topnav_hover.gif) no-repeat center top;
}


ul.menu li span { /*--Drop down trigger styles--*/
    width: 17px;
    height: 35px;
    float: left;
    background: url(../images/bullet.png) no-repeat center top;
}




ul.menu li span{background-position: center bottom; cursor: pointer;} /*--Hover effect for trigger--*/



ul.menu li ul {
    list-style: none;
    position: absolute; /*--Important - Keeps subnav from affecting main navigation flow--*/
    left: 0; top: 35px;
    background: #333;
    margin: 0; padding: 0;

    float: left;
    width: 170px;
    border: 1px solid #111;
}



ul.menu li ul.menu li{
    margin: 0; padding: 0;
    border-top: 1px solid #252525; /*--Create bevel effect--*/
    border-bottom: 1px solid #444; /*--Create bevel effect--*/
    clear: both;
    width: 170px;
}



html ul.menu li ul.menu li a {
    float: left;
    width: 145px;
    background: #333 url(dropdown_linkbg.gif) no-repeat 10px center;
    padding-left: 20px;
}



html ul.menu li ul.menu li a:hover { 
    background: #222 url(dropdown_linkbg.gif) no-repeat 10px center;
}

jQuery:

jQuery(function($) {

$('ul.menu li ul').hide();

    $("ul.menu li ul").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

    $("ul.menu li span").hover(function() { //When trigger is clicked...

                                        // alert("No error!"); 

        //Following events are applied to the subnav itself (moving subnav up and down)
        $(this).parent().find("ul.menu li ul").slideDown('fast').show(); //Drop down the subnav on click

        $(this).parent().hover(function() {
        }, function(){
            $(this).parent().find("ul.menu li ul").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
        });

        //Following events are applied to the trigger (Hover events for the trigger)
        }).hover(function() {
            $(this).addClass("subhover"); //On hover over, add class "subhover"
        }, function(){  //On Hover Out
            $(this).removeClass("subhover"); //On hover out, remove class "subhover"
    });

});

If i edit this line: $(this).parent().find("ul.menu li ul").slideDown('fast').show(); to this: ("ul.menu li ul").slideDown('fast').show(); It will show ALL the submenus for all parent items – obiviously I only want to show the submenu of the parent menu that I’m hovering over. When I try to add back in $(this).parent()... It won’t show any subs at all.

Thank you.

  • 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-26T21:06:00+00:00Added an answer on May 26, 2026 at 9:06 pm

    Thank you all for your help. Here’s the corrected working code to get the tutorial i mentioned in my original post to work with Drupal 7:

    Note: I’m using the main-menu as a block here.

    CSS:

    ul.menu {
        list-style: none;
        padding: 0 20px;
        margin: 0;
        float: left;
        width: 920px;
        background: #222;
        font-size: 1.2em;
        background: url(topnav_bg.gif) repeat-x;
        z-index:999;
    }
    
    
    
    ul.menu li {
        float: left;
        margin: 0;
        padding: 0 15px 0 0;
        position: relative; /*--Declare X and Y axis base for sub navigation--*/
    }
    
    
    
    ul.menu li a{
        padding: 10px 5px;
        color: #000;
        display: block;
        text-decoration: none;
        float: left;
    }
    
    ul.menu li a:hover{
        background: url(topnav_hover.gif) no-repeat center top;
    }
    
    
    ul.menu li span { /*--Drop down trigger styles--*/
        width: 17px;
        height: 35px;
        float: left;
        background: url(images/bullet.png) no-repeat center top;
    }
    
    
    ul.menu li span{background-position: center bottom; cursor: pointer;} /*--Hover effect for trigger--*/
    
    
    ul.menu li ul {
        list-style: none;
        position: absolute; /*--Important - Keeps subnav from affecting main navigation flow--*/
        left: 0; top: 35px;
        background: #333;
        margin: 0; padding: 0;
        display:none;
        float: left;
        width: 170px;
        border: 1px solid #111;
    }
    
    ul.menu li ul.menu li{
        margin: 0; padding: 0;
        border-top: 1px solid #252525; /*--Create bevel effect--*/
        border-bottom: 1px solid #444; /*--Create bevel effect--*/
        clear: both;
        width: 170px;
    }
    
    
    html ul.menu li ul.menu li a {
        float: left;
        width: 145px;
        background: #333 url(dropdown_linkbg.gif) no-repeat 10px center;
        padding-left: 20px;
    }
    
    
    html ul.menu li ul.menu li a:hover { 
        background: #222 url(dropdown_linkbg.gif) no-repeat 10px center;
    }
    

    jQuery:

    jQuery(function($) {
    
    
        $("ul.menu li ul").parent().append("<span></span>"); 
    
        $("ul.menu li span").click(function() { //When trigger is clicked...
    
    
            //Following events are applied to the subnav itself (moving subnav up and down)
            $(this).parent().find("ul").slideDown('fast').show(); //Drop down the subnav on click
    
            $(this).parent().hover(function() {
            }, function(){
                $(this).parent().find("ul").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
            });
    
            //Following events are applied to the trigger (Hover events for the trigger)
            }).hover(function() {
                $(this).addClass("subhover"); //On hover over, add class "subhover"
            }, function(){  //On Hover Out
                $(this).removeClass("subhover"); //On hover out, remove class "subhover"
        });
    
    });
    

    Partial page.tpl.php:

    <?php if ($page['navigation'] || $main_menu): ?>
          <div id="navigation"><div class="section clearfix">
    
            <?php print theme('links__system_main_menu', array(
              'links' => $main_menu,
              'attributes' => array(
                'id' => 'main-menu',
                'class' => array('links', 'inline', 'clearfix'),
              ),
              'heading' => array(
                'text' => t('Main menu'),
                'level' => 'h2',
                'class' => array('element-invisible'),
              ),
            )); ?>
    
            <?php print render($page['navigation']); ?>
    
          </div></div><!-- /.section, /#navigation -->
        <?php endif; ?>
    

    This implementation works without having to inject any additional classes into Drupal’s menu HTML.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.