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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:43:24+00:00 2026-05-24T18:43:24+00:00

Attached to my template, that I received from my slicer, there was a javascript

  • 0

Attached to my template, that I received from my slicer, there was a javascript file for coloring the menu items.
Now I need to convert the template to a Drupal template.
The javascript is based on the fact that every menu item has an id, according to the order of the items.
In Drupal, the menu items only have classes (menu-341, menu-342 etc.,). I know I can adjust the javascript, so it gets the menu items by class, but it actually isn’t possible because then I need to completely upset the whole file, what I try to prevent.

So can I add an ID to all my main menu items, something like ‘menu-item-1’, ‘menu-item-2’, etc.?
Should I do this in template.tpl.php, or directly change the output in page.tpl.php?

Thanks for help.

EDIT:
I’m desperate because I just don’t know how to fix this. Is there another way to color my menu items?
The script I’m using picks the menu items on their ascending id (custom-menu-item-id-x), and gives them a background, out of an array, wich associates with the ‘x’ of the ID. Four colors: color 1 for item 1, color 2 for item 2, color 1 for item 5 etc…..
Isn’t there another way to fix this? Couldn’t I let jQuery pick them automatically in the ascending order (first item it encounters gets the first background, second item second background etc.)? Please come up with ideas. I tried everything, in my opinion.

This is my current script:

//Sequence of the background colors from the menu items, from left to right.
var backgrounds = ["blue", "green", "pink", "purple"];

//Gives the menu items a style when hovering over it, in the sequence of the setting in the variable 'backgrounds', on top.
jQuery(document).ready(function MenuColor($){
    for (var i = 0; i <= 10 ; i++) {
        document.getElementById("custom-menu-item-id-" + (i + 1)).onmouseover = (function(valueOfI){ return function() {
        this.style.background = "url('images/" +  backgrounds[(valueOfI % backgrounds.length)] + ".jpg')";
        }; })(i);
        var ActiveLi = $('.active').attr('id');
        if("custom-menu-item-id-" + (i + 1) != ActiveLi) {
            document.getElementById("custom-menu-item-id-" + (i + 1)).onmouseout = function() {
                this.style.background = 'none'; 
            }
        }
    }
});
  • 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-24T18:43:24+00:00Added an answer on May 24, 2026 at 6:43 pm

    But I managed it finally by myself.
    First, I pasted this piece of code (copied from the Bartik page.tpl.php template) in my page.tpl.php:

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

    This placed the ‘main menu’ at the right place.
    BUT, everything I changed in menu.inc, or in template.php, didn’t apply to it.
    So, instead of placing that code there, I placed the BLOCK ‘main menu’ in the corresponding region , and suddenly I was able to change everything.

    So in my template.php I added this function, wich wrote the ID to the items.

    <?php
    /**
     * Returns HTML for a menu link and submenu.
     *
     * @param $variables
     *   An associative array containing:
     *   - element: Structured array data for a menu link.
     *
     * @ingroup themeable
     */
    function exofes_menu_link(array $variables) {
      $element = $variables['element'];
      $sub_menu = '';
    
      if ($element['#below']) {
        $sub_menu = drupal_render($element['#below']);
      }
      static $item_id = 0;
      $output = l($element['#title'], $element['#href'], $element['#localized_options']);  
      return '<li id="custom-menu-item-id-' . (++$item_id) . '"' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
    }
    ?>
    

    AND THAT WORKED :D!

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

Sidebar

Related Questions

The attached screenshot is from OS X/Firefox 3. Note that the center tab (an
In my code attached below, I'm trying to upload a file via ASP.NET. I
so I have attached a context menu (right-click menu) to a wpf listview. unfortunately,
I wrote an attached property that I can set on a window to extend
I would like to have a ListView that would have have items similar to
I have checked in FireFox Firebug and found that Keypress event is not attached
I tried to create a container for posible metadata that can be attached to
I have an Entity Framework POCO class that is generated by a T4 Template.
I'm developing an application in WPF (.NET 4). I have an attached property that
I have the following template String: Hello [Name] Please find attached [Invoice Number] which

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.