How to add css class attributes to the anchor element inside the links of a given menu by theme function Do I miss something or is it impossible to theme the link anchor HTML element &lt;ul class="main-menu"&gt;&lt;li&gt;&lt;a href="" class="put something in here"&gt;&lt;/li&gt;&lt;/ul&gt;  for a targeted menu on the theming level (theme functions)?

We can theme the &lt;li&gt; elements and the menu block elements with HOOK_menu_link_MENU_NAME(). Thanks to David Thomas for pointing that out to me. But I had no luck with targeting the nested anchors itself. The Devel array output and the drupal.org docs only brought me to theme_menu_item_link(), theme_links, theme_link(), and others, but I can't see an opportunity here to elegantly incept dynamic values for css classes on the anchor element?

I would like to add style class attributes to the &lt;a&gt; element in  ul > li of a given menu (not of all menus, thats what theme_links() does)... 



NOTES:


nested css targeting by altering the upper element is not an option
here, since the required css class is level sensitive and should NOT
be applied to the upper html element. 
And yes, I know the menu_attributes module. It's an awesome
module I use very often. But the approach is different. I don't want
to change the menu link data in the DB, but the output only.
There is an issue for the theme_links() function on drupal.org mentioning 
some trouble with its scope and how it works: https://drupal.org/node/588148


  theme_links(): Returns HTML for a set of links. => theme_links($variables)
  https://drupal.org/node/588148 => theme_links() is not really
  themeable [#588148] => Drupal core, theme system, normal, needs work,
  49 comments, 1 IRC mention

Another option would be to add &lt;span&gt; elements inside the anchor elements. I already did this for node objects but I don't know if this is possible here and if this is the right way to do it.
Edit: Here are two questions - 1 - 2 - on stackexchange I read thru' atm, since there are near issues discussed. Maybe it will enlighten me soon ... (Thanks to Clive, who has pointed me to the second one.)
I am probably looking at this upside down or backwards but, are you rendering this menu yourself, eg, you are calling theme('links', $variables) somewhere and can easily modify $variables?

If so, a quick look at the theme_links() function itself reveals the following comment...

/**
 * Returns HTML for a set of links.
 *
 * @param $variables
 *   An associative array containing:
 *   - links: An associative array of links to be themed. The key for each link
 *     is used as its CSS class. Each link should be itself an array, with the
 *     following elements:
 *     - title: The link text.
 *     - href: The link URL. If omitted, the 'title' is shown as a plain text
 *       item in the links list.
 *     - html: (optional) Whether or not 'title' is HTML. If set, the title
 *       will not be passed through check_plain().
 *     - attributes: (optional) Attributes for the anchor, or for the &lt;span&gt;
 *       tag used in its place if no 'href' is supplied. If element 'class' is
 *       included, it must be an array of one or more class names.
 *     If the 'href' element is supplied, the entire link array is passed to
 *     l() as its $options parameter.
 *   - attributes: A keyed array of attributes for the UL containing the
 *     list of links.
 *
 *  (rest of comment deleted)
 */


showing that what you need to do is put in an attributes key with each link, as, further on down in the code, when it is creating the link itself, it does, as the comment above also mentions, adds in the full $link as the $options parameter, eg...

$output .= l($link['title'], $link['href'], $link);


So, if you create an attributes key that points to an array with a key of class for whatever link needs a special class, and that key itself points to an array containing that name, this class will be added to the anchor.